aboutsummaryrefslogtreecommitdiffstats
path: root/thread.c
diff options
context:
space:
mode:
authorMatt Valentine-House <matt@eightbitraptor.com>2020-06-30 22:19:18 +0100
committerAaron Patterson <aaron.patterson@gmail.com>2020-09-10 08:48:51 -0700
commitef22af4db0e38db406cfc46987cbe03582de2da0 (patch)
treeebee7c25afce4527d5c23dd0481143ad2d4b7223 /thread.c
parent867204c4a558f318be9d39da47298d5ccc85ff17 (diff)
downloadruby-ef22af4db0e38db406cfc46987cbe03582de2da0.tar.gz
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
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/thread.c b/thread.c
index 063d96045e..4b563a5aa4 100644
--- a/thread.c
+++ b/thread.c
@@ -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;