mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/monitor.rb (MonitorMixin.mon_release): ensure the scheduled
thread to be alive when a thread is releasing a monitor. #2240 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@25420 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3b33b909d4
commit
69743fbd85
3 changed files with 41 additions and 3 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Wed Oct 21 01:19:56 2009 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/monitor.rb (MonitorMixin.mon_release): ensure the scheduled
|
||||||
|
thread to be alive when a thread is releasing a monitor. #2240
|
||||||
|
|
||||||
Wed Oct 21 00:28:52 2009 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
|
Wed Oct 21 00:28:52 2009 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
|
||||||
|
|
||||||
* lib/webrick/httpauth/digestauth.rb: typo in exception message fixed.
|
* lib/webrick/httpauth/digestauth.rb: typo in exception message fixed.
|
||||||
|
|
|
@ -288,11 +288,15 @@ module MonitorMixin
|
||||||
@mon_owner = Thread.current
|
@mon_owner = Thread.current
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# mon_release requires Thread.critical == true
|
||||||
def mon_release
|
def mon_release
|
||||||
@mon_owner = nil
|
@mon_owner = nil
|
||||||
t = @mon_waiting_queue.shift
|
while t = @mon_waiting_queue.shift || @mon_entering_queue.shift
|
||||||
t = @mon_entering_queue.shift unless t
|
if t.alive?
|
||||||
t.wakeup if t
|
t.wakeup
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def mon_enter_for_cond(count)
|
def mon_enter_for_cond(count)
|
||||||
|
|
|
@ -54,6 +54,32 @@ class TestMonitor < Test::Unit::TestCase
|
||||||
assert_equal((1..10).to_a, ary)
|
assert_equal((1..10).to_a, ary)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_killed_thread_in_synchronize
|
||||||
|
ary = []
|
||||||
|
queue = Queue.new
|
||||||
|
t1 = Thread.start {
|
||||||
|
queue.pop
|
||||||
|
@monitor.synchronize {
|
||||||
|
ary << :t1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
t2 = Thread.start {
|
||||||
|
queue.pop
|
||||||
|
@monitor.synchronize {
|
||||||
|
ary << :t2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@monitor.synchronize do
|
||||||
|
queue.enq(nil)
|
||||||
|
queue.enq(nil)
|
||||||
|
assert_equal([], ary)
|
||||||
|
t1.kill
|
||||||
|
t2.kill
|
||||||
|
ary << :main
|
||||||
|
end
|
||||||
|
assert_equal([:main], ary)
|
||||||
|
end
|
||||||
|
|
||||||
def test_try_enter
|
def test_try_enter
|
||||||
queue1 = Queue.new
|
queue1 = Queue.new
|
||||||
queue2 = Queue.new
|
queue2 = Queue.new
|
||||||
|
@ -94,7 +120,10 @@ class TestMonitor < Test::Unit::TestCase
|
||||||
assert_equal(true, result1)
|
assert_equal(true, result1)
|
||||||
assert_equal("bar", a)
|
assert_equal("bar", a)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_timedwait
|
||||||
|
cond = @monitor.new_cond
|
||||||
b = "foo"
|
b = "foo"
|
||||||
queue2 = Queue.new
|
queue2 = Queue.new
|
||||||
Thread.start do
|
Thread.start do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue