You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
psp-python/02.Threads/P2.17-Lock_como_parametro.py

28 lines
430 B

import threading
from time import time
def f_hilo(lock):
global x
for _ in range(1000000):
#lock.acquire()
for _ in range(100):
a=x
x=a+1
#lock.release()
x = 0
#tiempo_inicial = time()
lock = threading.Lock()
t1 = threading.Thread(target=f_hilo, args=(lock,))
t2 = threading.Thread(target=f_hilo, args=(lock,))
t1.start()
t2.start()
t1.join()
t2.join()
#print (time()-tiempo_inicial)
print (x)

Powered by Informatica FP.