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)
相关文章
- 03-25Python 锁 同步 互斥锁
- 03-25Go36-26-互斥锁与读写锁
- 03-2566 进程互斥锁的应用示例
- 03-25[转]Go 互斥锁(sync.Mutex)和 读写锁(sync.RWMutex)
- 03-25信号量和互斥锁
- 03-25RocketMQ官方为什么“异步刷盘建议用自旋锁,同步刷盘建议用重入锁”?
- 03-25python 之 并发编程(守护线程与守护进程的区别、线程互斥锁、死锁现象与递归锁、信号量、GIL全局解释器锁)
- 03-258.14 day32 TCP服务端并发 GIL解释器锁 python多线程是否有用 死锁与递归锁 信号量event事件线程q
- 03-25线程同步之读写锁
- 03-25PYTHON线程知识再研习D---可重入锁