import time
import threading
bar
= threading
.Barrier
(2)
threadingLock
= threading
.Lock
()
def server():
bar
.wait
()
threadingLock
.acquire
()
print(threading
.current_thread
().name
, '开始了')
threadingLock
.release
()
for i
in range(9):
time
.sleep
(1)
threading
.Thread
(target
=server
).start
()
Thread-2 开始了
Thread-1 开始了
Thread-4 开始了
Thread-3 开始了
Thread-6 开始了
Thread-5 开始了
Thread-8 开始了
Thread-7 开始了
观察结果,线程总是成对出现。
转载请注明原文地址: https://lol.8miu.com/read-12862.html