多线程锁
import threading
import time
num = 0
lock = threading.RLock()
def fun():
lock.acquire()
global num
num+=1
time.sleep(1)
print(num)
lock.release()
for i in range(10):
t =threading.Thread(target=fun)
t.start()
import threading
import time
num = 0
lock = threading.RLock()
def fun():
lock.acquire()
global num
num+=1
time.sleep(1)
print(num)
lock.release()
for i in range(10):
t =threading.Thread(target=fun)
t.start()