递归锁

# __author: "ZXYang"
# date: 2020/5/13
import threading


class MyThread(threading.Thread):

def __init__(self):
threading.Thread.__init__(self)
# self.num = num

def s(self):
lock.acquire()
print('aaa')
lock.acquire()
print('bbb')
lock.release()
lock.release()

def t(self):
lock.acquire()
print('aaa')
lock.acquire()
print('bbb')
lock.release()
lock.release()

def run(self):
self.s()
self.t()


if __name__ == '__main__':

lock = threading.RLock()

threads = []
for i in range(10):
threads.append(MyThread())

for t in threads:
t.start()
上一篇:C++ | 多线程编程(四) 信号量


下一篇:Python-4.21 死锁与递归锁