[前][次][番号順一覧][スレッド一覧]

ruby-changes:62882

From: Matt <ko1@a...>
Date: Fri, 11 Sep 2020 00:49:17 +0900 (JST)
Subject: [ruby-changes:62882] ef22af4db0 (master): If the GC runs before the Mutex's are initialised then we get a crash in pthread_mutex_lock.

https://git.ruby-lang.org/ruby.git/commit/?id=ef22af4db0

From ef22af4db0e38db406cfc46987cbe03582de2da0 Mon Sep 17 00:00:00 2001
From: Matt Valentine-House <matt@e...>
Date: Tue, 30 Jun 2020 22:19:18 +0100
Subject: 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

diff --git a/inits.c b/inits.c
index a3eec16..f8eba91 100644
--- a/inits.c
+++ b/inits.c
@@ -20,6 +20,7 @@ static void Init_builtin_prelude(void); https://github.com/ruby/ruby/blob/trunk/inits.c#L20
 void
 rb_call_inits(void)
 {
+    CALL(Thread_Mutex);
 #if USE_TRANSIENT_HEAP
     CALL(TransientHeap);
 #endif
diff --git a/thread.c b/thread.c
index 063d960..4b563a5 100644
--- a/thread.c
+++ b/thread.c
@@ -5423,6 +5423,16 @@ rb_thread_backtrace_locations_m(int argc, VALUE *argv, VALUE thval) https://github.com/ruby/ruby/blob/trunk/thread.c#L5423
     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) https://github.com/ruby/ruby/blob/trunk/thread.c#L5552
 	    /* 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;
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]