import threading
# lock = threading.RLock()
# RLock 递归锁
lock = threading.RLock()
Counter = [0]
def add(C):
lock.acquire()
C[0] = C[0] + 1
lock.release()
if __name__ == '__main__':
count = 0
threads = []
for i in range(10):
t = threading.Thread(target=add, args=[Counter])
threads.append(t)
for t in threads:
t.start()
t.join()
print(Counter)
相关文章
- 12-26python 之 并发编程(守护线程与守护进程的区别、线程互斥锁、死锁现象与递归锁、信号量、GIL全局解释器锁)
- 12-268.14 day32 TCP服务端并发 GIL解释器锁 python多线程是否有用 死锁与递归锁 信号量event事件线程q
- 12-26python2 logging模块在多进程和多线程混用下的一个坑
- 12-26python多线程相关知识点
- 12-26python基础之多线程的操作
- 12-26python-多线程
- 12-26Python面向对象01 /面向对象初识、面向对象结构、类、self、实例化对象
- 12-26Python并发编程——多线程与协程
- 12-26PYTHON线程知识再研习D---可重入锁
- 12-26小渣渣学习笔记 python day35【线程 进程 锁 生产者消费者总结 池 】