You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
418 B
25 lines
418 B
|
|
import threading
|
|
|
|
def ping(cond):
|
|
for _ in range(20):
|
|
with cond:
|
|
cond.wait()
|
|
print ("ping")
|
|
cond.notify()
|
|
|
|
def pong(cond):
|
|
for _ in range(20):
|
|
with cond:
|
|
cond.wait()
|
|
print ("pong")
|
|
cond.notify()
|
|
|
|
cond = threading.Condition()
|
|
|
|
t1= threading.Thread(target=ping, args=(cond,))
|
|
t2=threading.Thread(target=pong, args=(cond,))
|
|
t1.start()
|
|
t2.start()
|
|
with cond:
|
|
cond.notify() |