python 多线程-01 锁
Posted hurz
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 多线程-01 锁相关的知识,希望对你有一定的参考价值。
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)
以上是关于python 多线程-01 锁的主要内容,如果未能解决你的问题,请参考以下文章