3 ms·
Thank you, I believe you are right. I did try to make a race condition happen using += and am having a hard time. Here's my code import threading i =
by shrimpx 3y ago
Thank you, I believe you are right. I did try to make a race condition happen using += and am having a hard time. Here's my code
import threading
i = 0
def test():
global i
for x in range(1000000):
i += 1
threads = [threading.Thread(target=test) for t in range(20)]
for t in threads:
t.start()
for t in threads:
t.join()
assert i == 20000000, i
Presumably the assert should fail sometimes but I haven't been able to observe that.