Skip to content

Commit af001c9

Browse files
committed
Fix possible deadlock when waiting for mutex_threads
Usually when we wait for getting a lock on a mutex, we mark the waitingthread as blocked so another thread may steal our GC work. This isn't a good idea for the instance's mutex_threads though as the GC also acquires a lock on that mutex and we can end up in a dead lock. Since all places that use this lock only hold it briefly, marking the thread as blocked isn't really that beneficial anyway. The first place that got this wrong was MVM_proc_fork and I copied that mistake to MVM_spesh_stats_cleanup. Both are now fixed. Fixes GH#4462
1 parent a27efd3 commit af001c9

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/io/procops.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,9 +1251,9 @@ MVMint64 MVM_proc_fork(MVMThreadContext *tc) {
12511251
/* Allow MVM_io_eventloop_start to restart the thread if necessary */
12521252
instance->event_loop_thread = NULL;
12531253

1254-
MVM_gc_mark_thread_blocked(tc);
1254+
/* Do not mark thread blocked as the GC also tries to acquire
1255+
* mutex_threads and it's help only briefly by all holders anyway */
12551256
uv_mutex_lock(&instance->mutex_threads);
1256-
MVM_gc_mark_thread_unblocked(tc);
12571257

12581258
/* Check if we are single threaded and if true, fork() */
12591259
if (MVM_thread_cleanup_threads_list(tc, &instance->threads) == 1) {

src/spesh/stats.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,9 @@ void MVM_spesh_stats_cleanup(MVMThreadContext *tc, MVMObject *check_frames) {
670670
* consideration. */
671671
}
672672
else if (tc->instance->spesh_stats_version - ss->last_update > MVM_SPESH_STATS_MAX_AGE) {
673-
MVM_gc_mark_thread_blocked(tc);
673+
/* Do not mark thread blocked as the GC also tries to acquire
674+
* mutex_threads and it's help only briefly by all holders anyway */
674675
uv_mutex_lock(&tc->instance->mutex_threads);
675-
MVM_gc_mark_thread_unblocked(tc);
676676

677677
MVMThread *current = tc->instance->threads;
678678
int found = 0;

0 commit comments

Comments
 (0)