Re: [問題] blocking queue 實作
謝謝幫忙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://www.ptt.cc/bbs/Python/M.1532165146.A.897.html
推
07/21 18:11,
7年前
, 1F
07/21 18:11, 1F
→
07/21 18:12,
7年前
, 2F
07/21 18:12, 2F
推
07/21 19:59,
7年前
, 3F
07/21 19:59, 3F
推
07/21 21:19,
7年前
, 4F
07/21 21:19, 4F
推
07/22 08:54,
7年前
, 5F
07/22 08:54, 5F
→
07/22 08:55,
7年前
, 6F
07/22 08:55, 6F
原來的code 只用了一個lock
https://paste.ubuntu.com/p/dkqbMs8NKS/
先來兩個get,兩個都會卡在 wait
put, 然後會notify其中一個get 然後進行
此get完畢之後,又送了 notify給另外一個正在wait的get
2nd get醒來之後,因為是if語句,所以沒有繼續檢查que empty
直接執行popleft 所以出錯
※ 編輯: sean72 (172.89.32.145), 07/22/2018 10:22:10
推
07/22 10:44,
7年前
, 7F
07/22 10:44, 7F
討論串 (同標題文章)
Python 近期熱門文章
PTT數位生活區 即時熱門文章