1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

merges r21148 from trunk into ruby_1_9_1.

* 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: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@21160 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
yugui 2008-12-29 07:19:32 +00:00
parent 0d546bd1ff
commit a25b3c05e7
3 changed files with 26 additions and 4 deletions

View file

@ -1,3 +1,12 @@
Mon Dec 29 11:58:39 2008 Koichi Sasada <ko1@atdot.net>
* 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.
Mon Dec 29 07:15:16 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* cont.c: small RDoc fix mentioned from <radek.bulat at gmail.com>

View file

@ -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

View file

@ -2796,10 +2796,6 @@ rb_mutex_trylock(VALUE self)
VALUE locked = Qfalse;
GetMutexPtr(self, mutex);
if (mutex->th == GET_THREAD()) {
rb_raise(rb_eThreadError, "deadlock; recursive locking");
}
native_mutex_lock(&mutex->lock);
if (mutex->th == 0) {
mutex->th = GET_THREAD();
@ -2871,11 +2867,16 @@ lock_interrupt(void *ptr)
VALUE
rb_mutex_lock(VALUE self)
{
if (rb_mutex_trylock(self) == Qfalse) {
mutex_t *mutex;
rb_thread_t *th = GET_THREAD();
GetMutexPtr(self, mutex);
if (mutex->th == GET_THREAD()) {
rb_raise(rb_eThreadError, "deadlock; recursive locking");
}
while (mutex->th != th) {
int interrupted;
enum rb_thread_status prev_status = th->status;