编程语言
首页 > 编程语言> > python 多线程-01 锁

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)

标签:__,01,python,lock,Counter,RLock,threading,threads,多线程
来源: https://www.cnblogs.com/pythonPath/p/12448742.html