37,720
社区成员
发帖
与我相关
我的任务
分享
import threading
import time
def showa():
while True:
lockc.acquire()
print('a',end='')
locka.release()
time.sleep(0.1)
def showb():
while True:
locka.acquire()
print('b',end='')
lockb.release()
time.sleep(0.1)
def showc():
while True:
lockb.acquire()
print('c',end='\n')
lockc.release()
time.sleep(0.1)
if __name__=='__main__':
locka=threading.Lock()
lockb=threading.Lock()
lockc=threading.Lock()
t1=threading.Thread(target=showa)
t2=threading.Thread(target=showb)
t3=threading.Thread(target=showc)
locka.acquire()
lockb.acquire()
t1.start()
t2.start()
t3.start()