From 264889ec3d3d38fc1fd23c4fb48402f1367a8deb Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Thu, 17 Sep 2020 15:15:43 +0200 Subject: Fix Mutex#unlock with a scheduler and thread contention * It would hit "[BUG] unexpected THREAD_STOPPED" before. --- thread_sync.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'thread_sync.c') diff --git a/thread_sync.c b/thread_sync.c index 741bff6160..10ff9c49b1 100644 --- a/thread_sync.c +++ b/thread_sync.c @@ -402,20 +402,20 @@ 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)); + } else { + switch (cur->th->status) { + case THREAD_RUNNABLE: /* from someone else calling Thread#run */ + case THREAD_STOPPED_FOREVER: /* likely (rb_mutex_lock) */ + rb_threadptr_interrupt(cur->th); + goto found; + case THREAD_STOPPED: /* probably impossible */ + rb_bug("unexpected THREAD_STOPPED"); + case THREAD_KILLED: + /* not sure about this, possible in exit GC? */ + rb_bug("unexpected THREAD_KILLED"); + continue; + } } - - switch (cur->th->status) { - case THREAD_RUNNABLE: /* from someone else calling Thread#run */ - case THREAD_STOPPED_FOREVER: /* likely (rb_mutex_lock) */ - rb_threadptr_interrupt(cur->th); - goto found; - case THREAD_STOPPED: /* probably impossible */ - rb_bug("unexpected THREAD_STOPPED"); - case THREAD_KILLED: - /* not sure about this, possible in exit GC? */ - rb_bug("unexpected THREAD_KILLED"); - continue; - } } found: while (*th_mutex != mutex) { -- cgit v1.2.3