作者sean72 (.)
看板Python
标题Re: [问题] blocking queue 实作
时间Sat Jul 21 18:20:58 2018
※ 引述《sean72 (.)》之铭言:
: 标题: Re: [问题] blocking queue 实作
: 时间: Sat Jul 21 17:25:43 2018
:
: 谢谢帮忙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吗?
: 他是怎麽进入等待的?
:
:
: --
:
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 172.89.32.145
: ※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1532165146.A.897.html
: 推 flarehunter: wait会释放lock 所以别人才能拿lock再notify 07/21 18:11
: → flarehunter: https://docs.python.org/2/library/threading.html 07/21 18:12
C1 先取得lock
C1 wait and release lock
C2 取得lock
C2 wait and release lock
P1 此时P1 notify ,这个notify会按照wait的顺序,先给C1 ? 还是C1 C2任选?
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 172.89.32.145
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1532168461.A.5AF.html
1F:推 flarehunter: 官方文件没有保证notify会照wait的顺序 07/21 18:48