diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-09-16 20:42:15 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-09-16 20:42:15 +0000 |
commit | d9a45b677e559457bdef2118cd2829cce67501fa (patch) | |
tree | 6e4ecb0fde729d02bb78607316057119283ed679 /test/thread | |
parent | 0b01850bdc36f6d24a4fdc43ae2051e1fb3f86be (diff) |
* ext/thread/thread.c (lock_mutex): should take care of threads
not waiting any longer; there cases of a thread raising
exceptions. [ ruby-Bugs-11901 ]
* test/thread/test_thread.rb (test_mutex_exception_handling):
test for above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_6@13463 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/thread')
-rw-r--r-- | test/thread/test_thread.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/thread/test_thread.rb b/test/thread/test_thread.rb index 44ae3b338d..fe5fdeffda 100644 --- a/test/thread/test_thread.rb +++ b/test/thread/test_thread.rb @@ -77,5 +77,43 @@ class TC_Thread < Test::Unit::TestCase assert_equal("exit.", result[/.*\Z/], '[ruby-dev:30653]') } 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 end |