diff options
Diffstat (limited to 'test/ruby/test_thread.rb')
| -rw-r--r-- | test/ruby/test_thread.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index 0149e17d53..e180310505 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -797,4 +797,33 @@ Thread.new(Thread.current) {|mth| sleep 0.01 assert_equal(ary, ["run", "aborting", "aborting"]) end + + def test_mutex_owned + mutex = Mutex.new + + assert_equal(mutex.owned?, false) + mutex.synchronize { + # Now, I have the mutex + assert_equal(mutex.owned?, true) + } + assert_equal(mutex.owned?, false) + end + + def test_mutex_owned2 + begin + mutex = Mutex.new + th = Thread.new { + # lock forever + mutex.lock + sleep + } + + sleep 0.01 until th.status == "sleep" + # acquired another thread. + assert_equal(mutex.locked?, true) + assert_equal(mutex.owned?, false) + ensure + th.kill if th + end + end end |
