1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
Matt Valentine-House 2020-06-30 22:19:18 +01:00 committed by Aaron Patterson
parent 867204c4a5
commit ef22af4db0
Notes: git 2020-09-11 00:49:32 +09:00
2 changed files with 11 additions and 3 deletions

View file

@ -20,6 +20,7 @@ static void Init_builtin_prelude(void);
void
rb_call_inits(void)
{
CALL(Thread_Mutex);
#if USE_TRANSIENT_HEAP
CALL(TransientHeap);
#endif

View file

@ -5423,6 +5423,16 @@ rb_thread_backtrace_locations_m(int argc, VALUE *argv, VALUE thval)
return rb_vm_thread_backtrace_locations(argc, argv, thval);
}
void
Init_Thread_Mutex()
{
rb_thread_t *th = GET_THREAD();
rb_native_mutex_initialize(&th->vm->waitpid_lock);
rb_native_mutex_initialize(&th->vm->workqueue_lock);
rb_native_mutex_initialize(&th->interrupt_lock);
}
/*
* Document-class: ThreadError
*
@ -5542,9 +5552,6 @@ Init_Thread(void)
/* acquire global vm lock */
rb_global_vm_lock_t *gvl = rb_ractor_gvl(th->ractor);
gvl_acquire(gvl, th);
rb_native_mutex_initialize(&th->vm->waitpid_lock);
rb_native_mutex_initialize(&th->vm->workqueue_lock);
rb_native_mutex_initialize(&th->interrupt_lock);
th->pending_interrupt_queue = rb_ary_tmp_new(0);
th->pending_interrupt_queue_checked = 0;