mirror of
https://github.com/ruby/ruby.git
synced 2025-08-25 05:55:46 +02: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:
parent
0d546bd1ff
commit
a25b3c05e7
3 changed files with 26 additions and 4 deletions
9
thread.c
9
thread.c
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue