Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import threading
- import time
- n = 0
- array = [0]*10
- sem = threading.Semaphore()
- def proc1():
- global n, array
- while True:
- sem.acquire()
- array[n] = n
- n += 1
- sem.release()
- time.sleep(0.25)
- def proc2():
- global n, array
- while True:
- sem.acquire()
- array[n] = n
- n += 1
- sem.release()
- time.sleep(0.25)
- t = threading.Thread(target = proc1)
- t.start()
- t2 = threading.Thread(target = proc2)
- t2.start()
- print (array)
Add Comment
Please, Sign In to add comment