import threading
import time
def go1():
with con
:
for i
in range(0, 10, 2):
time
.sleep
(1)
print(threading
.current_thread
().name
, i
)
con
.wait
()
con
.notify
()
def go2():
with con
:
for i
in range(1, 10, 2):
time
.sleep
(1)
print(threading
.current_thread
().name
, i
)
con
.notify
()
con
.wait
()
con
= threading
.Condition
()
threading
.Thread
(target
=go1
).start
()
threading
.Thread
(target
=go2
).start
()
Thread-1 0
Thread-2 1
Thread-1 2
Thread-2 3
Thread-1 4
Thread-2 5
Thread-1 6
Thread-2 7
Thread-1 8
Thread-2 9
转载请注明原文地址: https://lol.8miu.com/read-16430.html