Skip to content

Commit 5d5a150

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 eada635 commit 5d5a150

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
@@ -5259,6 +5259,16 @@ rb_thread_backtrace_locations_m(int argc, VALUE *argv, VALUE thval)
52595259
return rb_vm_thread_backtrace_locations(argc, argv, thval);
52605260
}
52615261

5262+
void
5263+
Init_Thread_Mutex()
5264+
{
5265+
rb_thread_t *th = GET_THREAD();
5266+
5267+
rb_native_mutex_initialize(&th->vm->waitpid_lock);
5268+
rb_native_mutex_initialize(&th->vm->workqueue_lock);
5269+
rb_native_mutex_initialize(&th->interrupt_lock);
5270+
}
5271+
52625272
/*
52635273
* Document-class: ThreadError
52645274
*
@@ -5378,9 +5388,6 @@ Init_Thread(void)
53785388
/* acquire global vm lock */
53795389
gvl_init(th->vm);
53805390
gvl_acquire(th->vm, th);
5381-
rb_native_mutex_initialize(&th->vm->waitpid_lock);
5382-
rb_native_mutex_initialize(&th->vm->workqueue_lock);
5383-
rb_native_mutex_initialize(&th->interrupt_lock);
53845391

53855392
th->pending_interrupt_queue = rb_ary_tmp_new(0);
53865393
th->pending_interrupt_queue_checked = 0;

0 commit comments

Comments
 (0)