关于线程,博主写过java线程详解基本上把java线程的基础知识都讲解到位了,但是那还远远不够,多线程的存在就是为了让多个线程去协作来完成某一具体任务,比如生产者与消费者模型,因此了解线程间的协作是非常重要的,本博客主要讲解多个线程之间使用wait()/notify()/notifyAll()来进行交互的场景. 一wait()/notify()/notifyAll(): 首先我们来看一下它们的函数定义: /* Causes the current thread to wait until ano…
#1.生产者和消费者模型producer and consumer modelimport timedef producer(): ret = [] for i in range(2): time.sleep(0.2) ret.append("包子%s" %i) return retdef consumer(res): for index,baozi in enumerate(res): time.sleep(0.2) print("第%s个人,吃了%s" %(in…