summaryrefslogtreecommitdiff
path: root/ext/thread
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-03-16 07:27:09 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-03-16 07:27:09 +0000
commit15b97d196a7ea7097d2c9979fa0f46a0c3e702d4 (patch)
treeaeb1e5f2566bce1625f1a53a41980c7af12b544b /ext/thread
parent89150c9ecb8b5625d55c6a90958eeb63e3d29a33 (diff)
* ext/thread/thread.c (wait_condvar, lock_mutex): Fix a problem in
ConditionVariable#wait that occurs when two threads that are trying to access the condition variable are also in concurrence for the given mutex; submitted by: Sylvain Joyeux <sylvain.joyeux AT m4x.org> and MenTaLguY <mental AT rydia.net> in [ruby-core:10598]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@12068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/thread')
-rw-r--r--ext/thread/thread.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/ext/thread/thread.c b/ext/thread/thread.c
index e9dde37a18..54681a8c90 100644
--- a/ext/thread/thread.c
+++ b/ext/thread/thread.c
@@ -390,7 +390,7 @@ rb_mutex_try_lock(VALUE self)
*
*/
-static void
+static VALUE
lock_mutex(Mutex *mutex)
{
VALUE current;
@@ -405,6 +405,7 @@ lock_mutex(Mutex *mutex)
mutex->owner = current;
rb_thread_critical = 0;
+ return Qnil;
}
static VALUE
@@ -623,18 +624,12 @@ static void
wait_condvar(ConditionVariable *condvar, Mutex *mutex)
{
rb_thread_critical = 1;
- if (!RTEST(mutex->owner)) {
+ if (rb_thread_current() != mutex->owner) {
rb_thread_critical = 0;
- return;
+ rb_raise(rb_eThreadError, "not owner of the synchronization mutex");
}
- if (mutex->owner != rb_thread_current()) {
- rb_thread_critical = 0;
- rb_raise(rb_eThreadError, "Not owner");
- }
- mutex->owner = Qnil;
- wait_list(&condvar->waiting);
-
- lock_mutex(mutex);
+ unlock_mutex_inner(mutex);
+ rb_ensure(wait_list, (VALUE)&condvar->waiting, lock_mutex, (VALUE)mutex);
}
static VALUE