aboutsummaryrefslogtreecommitdiffstats
path: root/thread_pthread.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-27 23:29:44 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-27 23:29:44 +0000
commitb03b727b779efad396e4b2121e71d36a5539da3a (patch)
tree4c5835cd38934692b3291de58aceb9d88c7a6b0c /thread_pthread.c
parent46014f40f354fc73372a9672eda0465325b5a1f2 (diff)
downloadruby-b03b727b779efad396e4b2121e71d36a5539da3a.tar.gz
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") git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64579 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_pthread.c')
-rw-r--r--thread_pthread.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/thread_pthread.c b/thread_pthread.c
index fa79b03c55..dca30bd026 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -1320,6 +1320,7 @@ ubf_select(void *ptr)
{
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)
* 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);