summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-24 07:01:18 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-24 07:01:18 +0000
commit1adef150721a42b9efe97ebc18de535040810e7a (patch)
tree871d7671561891a833a3381d7d0ee1c1d18fca39
parent0fa6a335d10db5a9a717bf9073f7bd6964fc8c85 (diff)
* lib/thread.rb (ConditionVariable#broadcast): use Mutex
instead of Thread.exclusive. * lib/monitor.rb (MonitorMixin#mon_exit): unset @mon_owner before calling Mutex#unlock. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11848 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--lib/monitor.rb2
-rw-r--r--lib/thread.rb9
-rw-r--r--test/monitor/test_monitor.rb2
4 files changed, 17 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index a1229ec1748..1ba9f7bb359 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Sat Feb 24 15:57:19 2007 Shugo Maeda <shugo@ruby-lang.org>
+
+ * lib/thread.rb (ConditionVariable#broadcast): use Mutex
+ instead of Thread.exclusive.
+
+ * lib/monitor.rb (MonitorMixin#mon_exit): unset @mon_owner
+ before calling Mutex#unlock.
+
Sat Feb 24 15:51:45 2007 Minero Aoki <aamine@loveruby.net>
* parse.y (program): remove useless assignment to reduce warning.
diff --git a/lib/monitor.rb b/lib/monitor.rb
index a40d9247260..b5567475778 100644
--- a/lib/monitor.rb
+++ b/lib/monitor.rb
@@ -174,8 +174,8 @@ module MonitorMixin
mon_check_owner
@mon_count -=1
if @mon_count == 0
- @mon_mutex.unlock
@mon_owner = nil
+ @mon_mutex.unlock
end
end
diff --git a/lib/thread.rb b/lib/thread.rb
index 96e7875bea7..7dd4b1115d1 100644
--- a/lib/thread.rb
+++ b/lib/thread.rb
@@ -54,6 +54,7 @@ class ConditionVariable
#
def initialize
@waiters = []
+ @waiters_mutex = Mutex.new
end
#
@@ -62,7 +63,9 @@ class ConditionVariable
def wait(mutex)
begin
# TODO: mutex should not be used
- @waiters.push(Thread.current)
+ @waiters_mutex.synchronize do
+ @waiters.push(Thread.current)
+ end
mutex.sleep
end
end
@@ -72,7 +75,7 @@ class ConditionVariable
#
def signal
begin
- t = @waiters.shift
+ t = @waiters_mutex.synchronize { @waiters.shift }
t.run if t
rescue ThreadError
retry
@@ -85,7 +88,7 @@ class ConditionVariable
def broadcast
# TODO: imcomplete
waiters0 = nil
- Thread.exclusive do
+ @waiters_mutex.synchronize do
waiters0 = @waiters.dup
@waiters.clear
end
diff --git a/test/monitor/test_monitor.rb b/test/monitor/test_monitor.rb
index b539cb3cca6..064471eecb9 100644
--- a/test/monitor/test_monitor.rb
+++ b/test/monitor/test_monitor.rb
@@ -94,7 +94,9 @@ class TestMonitor < Test::Unit::TestCase
assert_equal(true, result1)
assert_equal("bar", a)
end
+ end
+ def _test_timedwait
b = "foo"
queue2 = Queue.new
Thread.start do