ruby-changes:52370
From: normal <ko1@a...>
Date: Tue, 28 Aug 2018 08:29:49 +0900 (JST)
Subject: [ruby-changes:52370] normal:r64579 (trunk): thread_pthread.c: fix deadlock on test_thread.rb::test_signal_at_join
normal 2018-08-28 08:29:44 +0900 (Tue, 28 Aug 2018) New Revision: 64579 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64579 Log: thread_pthread.c: fix deadlock on test_thread.rb::test_signal_at_join Fixes: r64575 ("avoid lock ping-pong in do_gvl_timer & ubf_select") Modified files: trunk/thread_pthread.c Index: thread_pthread.c =================================================================== --- thread_pthread.c (revision 64578) +++ thread_pthread.c (revision 64579) @@ -1320,6 +1320,7 @@ ubf_select(void *ptr) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1320 { rb_thread_t *th = (rb_thread_t *)ptr; rb_vm_t *vm = th->vm; + const rb_thread_t *cur = ruby_thread_from_native(); /* may be 0 */ register_ubf_list(th); @@ -1328,9 +1329,12 @@ ubf_select(void *ptr) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1329 * Therefore, we repeatedly call ubf_wakeup_thread() until a target thread * exit from ubf function. We must have a timer to perform this operation. * We use double-checked locking here because this function may be called - * while vm->gvl.lock is held in do_gvl_timer + * while vm->gvl.lock is held in do_gvl_timer. + * There is also no need to start a timer if we're the designated + * sigwait_th thread, otherwise we can deadlock with a thread + * in unblock_function_clear. */ - if (vm->gvl.timer != ruby_thread_from_native()) { + if (cur != vm->gvl.timer && cur != sigwait_th) { rb_native_mutex_lock(&vm->gvl.lock); if (!vm->gvl.timer) { rb_thread_wakeup_timer_thread(-1); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/