Guest User

Untitled

a guest
Jun 18th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. import threading
  2. import time
  3.  
  4.  
  5. foo = 0
  6.  
  7. def race_cond():
  8. flag = threading.Event()
  9.  
  10. def mutator():
  11. flag.wait()
  12. foo += 1
  13. foo -= 1
  14. ts = [threading.Thread(target=mutator)
  15. for i in range(100000)]
  16. [t.start() for t in ts]
  17. flag.set()
  18. [t.join() for t in ts]
  19.  
  20. for i in range(100):
  21. print(f'Expect 0, actual: {foo}')
Add Comment
Please, Sign In to add comment