Re: [问题] blocking queue 实作

楼主: sean72 (.)   2018-07-21 17:25:43
谢谢帮忙review
: 推 flarehunter: 在空的时候同时有2个get()和1个put()可能会坏掉 07/20 23:30
: → flarehunter: 有两个MyQueue物件也会坏掉 另外为什么要继承Thread? 07/20 23:31
https://paste.ubuntu.com/p/Zjh3y6ychm/
抄了source code,改成这样
Consumer1先跑,取得了self.not_empty,并且因为que == 0
所以等在while loop里 (wait())
Consumer2接着跑,此时C2能取得self.not_empty lock吗?
他是怎么进入等待的?
作者: flarehunter (Range)   2018-07-21 18:11:00
wait会释放lock 所以别人才能拿lock再notifyhttps://docs.python.org/2/library/threading.html
作者: cutekid (可爱小孩子)   2018-07-21 19:59:00
好奇原来的code在empty时,遇到两个get一个put为什么会坏
作者: flarehunter (Range)   2018-07-21 21:19:00
因为他用if不是while
作者: cutekid (可爱小孩子)   2018-07-22 08:54:00
嗯,我用if的状况去分析,还是看不出会出问题sean72大大,你有看出问题吗了解了,谢谢 s 大还有 f 大

Links booklink

Contact Us: admin [ a t ] ucptt.com