daily pastebin goal
28%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top