线程锁
import threading,time
num = 1
lock = threading.Lock() #申请一把锁
def run():
time.sleep(1)
global num
lock.acquire() #加锁
num+=1
lock.release() #解锁
ts = []
for i in range(100):
t = threading.Thread(target=run)
t.start()
ts.append(t)
[t.join() for t in ts]
print(num)