From d760f97172fd9e00c21b12e93ccdf9908f144be0 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 6 Jun 2002 02:43:02 +0000 Subject: * 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 --- ChangeLog | 4 ++++ lib/thread.rb | 22 +++++++--------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2c12d6188d..283b9bf740 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Thu Jun 6 11:42:15 2002 Nobuyoshi Nakada + + * lib/thread.rb (Queue::pop): get rid of race condition. + Tue Jun 4 18:28:37 2002 WATANABE Hirofumi * ext/socket/extconf.rb: The IPv6 stack of Cygwin is still incomplete. 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 -- cgit v1.2.3