Advertisement
Guest User

Untitled

a guest
Jun 14th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. #threading s barrijerom
  2.  
  3. import threading
  4.  
  5. result = 0
  6. lock = threading.Lock()
  7. barrier = threading.Barrier(3)
  8.  
  9. def add (start, stop):
  10.     global result
  11.     global barrier
  12.     for i in range(start, stop)
  13.         with lock:
  14.             result = result + i**2
  15.    
  16.     barrier.wait()
  17.    
  18. t1 = threading.Thread(target = add, args(0, 15001))
  19. t2 = threading.Thread(target = add, agrs(15001, 30001))
  20. t3 = threading.Thread(target = add, agrs(30001, 500001))
  21.  
  22. t1.start()
  23. t2.start()
  24. t3.start()
  25.  
  26. t1.join()
  27. t2.join()
  28. t3.join()
  29.  
  30. print(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement