diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-06-06 02:43:02 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-06-06 02:43:02 +0000 |
commit | d760f97172fd9e00c21b12e93ccdf9908f144be0 (patch) | |
tree | 88e1c3ad651a50f282277931a3e0596b1bf98be5 /lib/thread.rb | |
parent | 6956135b4b174c02221b62b2f0017d9fb3520c9c (diff) |
* lib/thread.rb (Queue::pop): get rid of race condition.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/thread.rb')
-rw-r--r-- | lib/thread.rb | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/lib/thread.rb b/lib/thread.rb index a398317461..7666bccecf 100644 --- a/lib/thread.rb +++ b/lib/thread.rb @@ -173,22 +173,14 @@ class Queue alias enq push def pop(non_block=false) - Thread.critical = true - begin - loop do - if @que.empty? - if non_block - raise ThreadError, "queue empty" - end - @waiting.push Thread.current - Thread.stop - else - return @que.shift - end - end - ensure - Thread.critical = false + while (Thread.critical = true; @que.empty?) + raise ThreadError, "queue empty" if non_block + @waiting.push Thread.current + Thread.stop end + @que.shift + ensure + Thread.critical = false end alias shift pop alias deq pop |