Guest User

Untitled

a guest
Mar 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. import threading
  2. import time
  3.  
  4. n = 0
  5. array = [0]*10
  6. sem = threading.Semaphore()
  7.  
  8. def proc1():
  9. global n, array
  10. while True:
  11. sem.acquire()
  12. array[n] = n
  13. n += 1
  14. sem.release()
  15. time.sleep(0.25)
  16.  
  17. def proc2():
  18. global n, array
  19. while True:
  20. sem.acquire()
  21. array[n] = n
  22. n += 1
  23. sem.release()
  24. time.sleep(0.25)
  25.  
  26.  
  27. t = threading.Thread(target = proc1)
  28. t.start()
  29. t2 = threading.Thread(target = proc2)
  30. t2.start()
  31.  
  32. print (array)
Add Comment
Please, Sign In to add comment