Skip to content

Commit a8db42e

Browse files
If the GC runs before the Mutex's are initialised then we get a crash in pthread_mutex_lock.
It is possible for GC to run during initialisation due to objects being allocated
1 parent b52513e commit a8db42e

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

inits.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static void Init_builtin_prelude(void);
2020
void
2121
rb_call_inits(void)
2222
{
23+
CALL(Thread_Mutex);
2324
#if USE_TRANSIENT_HEAP
2425
CALL(TransientHeap);
2526
#endif

thread.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5423,6 +5423,16 @@ rb_thread_backtrace_locations_m(int argc, VALUE *argv, VALUE thval)
54235423
return rb_vm_thread_backtrace_locations(argc, argv, thval);
54245424
}
54255425

5426+
void
5427+
Init_Thread_Mutex()
5428+
{
5429+
rb_thread_t *th = GET_THREAD();
5430+
5431+
rb_native_mutex_initialize(&th->vm->waitpid_lock);
5432+
rb_native_mutex_initialize(&th->vm->workqueue_lock);
5433+
rb_native_mutex_initialize(&th->interrupt_lock);
5434+
}
5435+
54265436
/*
54275437
* Document-class: ThreadError
54285438
*
@@ -5542,9 +5552,6 @@ Init_Thread(void)
55425552
/* acquire global vm lock */
55435553
rb_global_vm_lock_t *gvl = rb_ractor_gvl(th->ractor);
55445554
gvl_acquire(gvl, th);
5545-
rb_native_mutex_initialize(&th->vm->waitpid_lock);
5546-
rb_native_mutex_initialize(&th->vm->workqueue_lock);
5547-
rb_native_mutex_initialize(&th->interrupt_lock);
55485555

55495556
th->pending_interrupt_queue = rb_ary_tmp_new(0);
55505557
th->pending_interrupt_queue_checked = 0;

0 commit comments

Comments
 (0)