Skip to content

Commit 7018acc

Browse files
author
normal
committed
process.c (waitpid_nogvl): prevent conflicting use of sleep_cond
We reuse sleep_cond for waitpid notifications as well as GVL waiting. So we must take care to not hold onto sleep_cond when we try to reacquire GVL. [ruby-core:88183] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 56491af commit 7018acc

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

process.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,9 @@ waitpid_nogvl(void *x)
11441144
rb_sigwait_fd_put(th, sigwait_fd);
11451145
}
11461146
else {
1147+
if (!w->cond)
1148+
w->cond = rb_sleep_cond_get(w->ec);
1149+
11471150
/* another thread calling rb_sigwait_sleep will process
11481151
* signals for us */
11491152
if (SIGCHLD_LOSSY) {
@@ -1152,6 +1155,16 @@ waitpid_nogvl(void *x)
11521155
rb_native_cond_wait(w->cond, &th->interrupt_lock);
11531156
}
11541157
}
1158+
1159+
/*
1160+
* we must release th->native_thread_data.sleep_cond when
1161+
* re-acquiring GVL:
1162+
*/
1163+
if (w->cond) {
1164+
rb_sleep_cond_put(w->cond);
1165+
w->cond = 0;
1166+
}
1167+
11551168
rb_native_mutex_unlock(&th->interrupt_lock);
11561169

11571170
if (sigwait_fd >= 0)
@@ -1183,7 +1196,10 @@ waitpid_cleanup(VALUE x)
11831196
list_del(&w->wnode);
11841197
rb_native_mutex_unlock(&vm->waitpid_lock);
11851198
}
1186-
rb_sleep_cond_put(w->cond);
1199+
1200+
/* we may have never released and re-acquired GVL */
1201+
if (w->cond)
1202+
rb_sleep_cond_put(w->cond);
11871203

11881204
return Qfalse;
11891205
}

0 commit comments

Comments
 (0)