From 5c13dd59db1ee6c04cdac4ce2ee97d5934115439 Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 17 Mar 2000 08:58:21 +0000 Subject: 2000-03-17 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/thread.rb | 53 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 13 deletions(-) (limited to 'lib/thread.rb') diff --git a/lib/thread.rb b/lib/thread.rb index 22610f2992..9edda48abe 100644 --- a/lib/thread.rb +++ b/lib/thread.rb @@ -63,10 +63,14 @@ class Mutex def unlock return unless @locked Thread.critical = true - t = @waiting.shift @locked = false + begin + t = @waiting.shift + t.wakeup if t + rescue ThreadError + retry + end Thread.critical = false - t.run if t self end @@ -82,9 +86,13 @@ class Mutex def exclusive_unlock return unless @locked Thread.exclusive do - t = @waiting.shift @locked = false - t.wakeup if t + begin + t = @waiting.shift + t.wakeup if t + rescue ThreadError + retry + end yield end self @@ -105,8 +113,12 @@ class ConditionVariable end def signal - t = @waiters.shift - t.run if t + begin + t = @waiters.shift + t.run if t + rescue ThreadError + retry + end end def broadcast @@ -116,7 +128,10 @@ class ConditionVariable @waiters.clear end for t in waiters0 - t.run + begin + t.run + rescue ThreadError + end end end end @@ -133,9 +148,13 @@ class Queue def push(obj) Thread.critical = true @que.push obj - t = @waiting.shift + begin + t = @waiting.shift + t.wakeup if t + rescue ThreadError + retry + end Thread.critical = false - t.run if t end alias enq push @@ -201,8 +220,12 @@ class SizedQueue