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 | f0661f41ab51cadb3c348a14791d52bba19d9cfa (patch) | |
| tree | 88e1c3ad651a50f282277931a3e0596b1bf98be5 | |
| parent | 9676f70b0cc7ecb9b6255a785f60fb7cbba4a596 (diff) | |
| download | ruby-f0661f41ab51cadb3c348a14791d52bba19d9cfa.tar.gz ruby-f0661f41ab51cadb3c348a14791d52bba19d9cfa.tar.xz ruby-f0661f41ab51cadb3c348a14791d52bba19d9cfa.zip | |
* lib/thread.rb (Queue::pop): get rid of race condition.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@2527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 4 | ||||
| -rw-r--r-- | lib/thread.rb | 22 |
2 files changed, 11 insertions, 15 deletions
@@ -1,3 +1,7 @@ +Thu Jun 6 11:42:15 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net> + + * lib/thread.rb (Queue::pop): get rid of race condition. + Tue Jun 4 18:28:37 2002 WATANABE Hirofumi <eban@ruby-lang.org> * ext/socket/extconf.rb: The IPv6 stack of Cygwin is still incomplete. diff --git a/lib/thread.rb b/lib/thread.rb index a39831746..7666bccec 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 |
