Python 锁 同步 互斥锁

import time
from threading import Lock,Thread
num = 100
def f1(loc):
loc.acquire()
global num
tmp = num
tmp -= 1
time.sleep(0.001)
num = tmp
loc.release()
if __name__ == '__main__':
t_loc = Lock()
t_list = []
for i in range(10):
t = Thread(target=f1,args=(t_loc,))
t.start()
t_list.append(t)
[tt.join() for tt in t_list]
print("主线程的num:",num)
上一篇:BZOJ3585&3339mex——主席树


下一篇:spark优化之优化数据结构