From d01954632d7cd6574d51c8cc95b832ad5f9de62d Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Thu, 17 Sep 2020 17:26:52 +0200 Subject: [PATCH] Add missing goto found; * To still remove the lock from the Thread's list of acquired locks. * Also to not wake up other waiters and preserve blocking behavior. --- test/fiber/scheduler.rb | 3 ++- thread_sync.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test/fiber/scheduler.rb b/test/fiber/scheduler.rb index 193a824f7f..43edcb27ed 100644 --- a/test/fiber/scheduler.rb +++ b/test/fiber/scheduler.rb @@ -135,7 +135,8 @@ class Scheduler @locking -= 1 end - # Used when synchronization wakes up a previously-blocked fiber (Mutex#unlock, Queue#push, ...) + # Used when synchronization wakes up a previously-blocked fiber (Mutex#unlock, Queue#push, ...). + # This might be called from another thread. def unblock(blocker, fiber) # p [__method__, blocker, fiber] @lock.synchronize do diff --git a/thread_sync.c b/thread_sync.c index 10ff9c49b1..67d796233c 100644 --- a/thread_sync.c +++ b/thread_sync.c @@ -402,6 +402,7 @@ rb_mutex_unlock_th(rb_mutex_t *mutex, rb_thread_t *th, rb_fiber_t *fiber) if (cur->th->scheduler != Qnil) { rb_scheduler_unblock(cur->th->scheduler, cur->self, rb_fiberptr_self(cur->fiber)); + goto found; } else { switch (cur->th->status) { case THREAD_RUNNABLE: /* from someone else calling Thread#run */