Python - queue
import threading,time,queue
q=queue.Queue(maxsize = 10)
def product(name):
count = 1
while True:
q.put(count)
print("%s生产了%s个骨头"%(name,count))
count += 1
time.sleep(0.5)
def consumer(name):
while True:
print("%s 消费了 %s 个骨头"%(name,q.get()))
time.sleep(1)
p=threading.Thread(target=product,args=("xsy",))
c=threading.Thread(target=consumer,args=("a",))
c1=threading.Thread(target=consumer,args=("b",))
p.start()
c.start()
c1.start()