summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-06-06 06:16:25 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-06-06 06:16:25 +0000
commitd18b653719687756c82c7c800dee5e91b388fefd (patch)
treed64ce6d7598471d859d0eb4696a3ba5b49845bd2 /test
parent1acfb03370704aee624b7a1e5ccf4776f40f2895 (diff)
merge revision(s) 23432:
* eval.c (rb_thread_join), ext/thread/thread.c (wake_one): adjusts targets of rest waiting threads to join. [ruby-core:23457] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@35942 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/thread/test_thread.rb63
1 files changed, 63 insertions, 0 deletions
diff --git a/test/thread/test_thread.rb b/test/thread/test_thread.rb
index 699f4fe406..e3246d149c 100644
--- a/test/thread/test_thread.rb
+++ b/test/thread/test_thread.rb
@@ -86,5 +86,68 @@ class TC_Thread < Test::Unit::TestCase
assert_nothing_raised("[ruby-dev:37545]") {assert_equal(1, queue.pop)}
assert(queue.empty?)
end
+
+ # This test checks that a thread in Mutex#lock which is raised is
+ # completely removed from the wait_list of the mutex
+ def test_mutex_exception_handling
+ m = Mutex.new
+ m.lock
+
+ sleeping = false
+ t = Thread.new do
+ begin
+ m.lock
+ rescue
+ end
+
+ sleeping = true
+ # Keep that thread alive: if the thread returns, the test method
+ # won't be able to check that +m+ has not been taken (dead mutex
+ # owners are ignored)
+ sleep
+ end
+
+ # Wait for t to wait for the mutex and raise it
+ while true
+ sleep 0.1
+ break if t.stop?
+ end
+ t.raise ArgumentError
+ assert(t.alive? || sleeping)
+
+ # Wait for +t+ to reach the sleep
+ while true
+ sleep 0.1
+ break if t.stop?
+ end
+
+ # Now unlock. The mutex should be free, so Mutex#unlock should return nil
+ assert(! m.unlock)
+ end
+
+ def test_mutex_join
+ m = Mutex.new
+ m.lock
+ wt2 = Thread.new do
+ m.lock
+ sleep 0.5
+ m.unlock
+ end
+
+ # Ensure wt2 is waiting on m
+ sleep 0.1
+
+ wt1 = Thread.new do
+ m.lock
+ m.unlock
+ end
+ # Ensure wt1 is waiting on m
+ sleep 0.1
+
+ # Give it to wt2
+ m.unlock
+
+ assert_nothing_raised {wt1.join}
+ end
end