From 58ecf3244258837e0a8f0d7cab89effad94c7fa0 Mon Sep 17 00:00:00 2001 From: ko1 Date: Mon, 29 Dec 2008 03:03:09 +0000 Subject: * thread.c (rb_mutex_trylock): return false if Mutex owned by current thread. [ruby-core:20943] * thread.c (rb_mutex_lock): check dead lock (recursive lock) here. * test/ruby/test_thread.rb: add a test. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@21148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_thread.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index 97e58cd9e..b460cadea 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -438,6 +438,18 @@ class TestThread < Test::Unit::TestCase assert_equal(false, m3.locked?) end + def test_mutex_trylock + m = Mutex.new + assert_equal(true, m.try_lock) + assert_equal(false, m.try_lock, '[ruby-core:20943]') + + Thread.new{ + assert_equal(false, m.try_lock) + }.join + + m.unlock + end + def test_recursive_error o = Object.new def o.inspect -- cgit