diff options
author | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-04 16:02:07 +0000 |
---|---|---|
committer | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-04 16:02:07 +0000 |
commit | bbfbf662cceb6e7d8dc769ca365c563b9c073592 (patch) | |
tree | 9ea0a75f1d52fd7a2be933c5342cbfc290e51adb /test/ruby | |
parent | 1bdf339516c9886db6f950da6f5506c4f94baa65 (diff) |
* thread.c (rb_mutex_owned_p): new method that return current
thread have the target mutex or not. [Feature #7505] [ruby-dev:46697]
* test/ruby/test_thread.rb (test_mutex_owned, test_mutex_owned2):
test for the above.
* NEWS: new for the above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-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 |