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

ruby-changes:64534

From: Koichi <ko1@a...>
Date: Thu, 24 Dec 2020 04:31:09 +0900 (JST)
Subject: [ruby-changes:64534] 7340e7f827 (master): introduce rb_ractor_atfork()

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

From 7340e7f82780f529d80490045f5ea3e2559d563c Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Thu, 24 Dec 2020 04:29:59 +0900
Subject: introduce rb_ractor_atfork()

to reset main ractor at fork().

diff --git a/ractor.c b/ractor.c
index 26322f5..d9a8e07 100644
--- a/ractor.c
+++ b/ractor.c
@@ -1477,6 +1477,24 @@ rb_ractor_main_alloc(void) https://github.com/ruby/ruby/blob/trunk/ractor.c#L1477
     return r;
 }
 
+#if defined(HAVE_WORKING_FORK)
+void
+rb_ractor_atfork(rb_vm_t *vm, rb_thread_t *th)
+{
+    // initialize as a main ractor
+    vm->ractor.cnt = 0;
+    vm->ractor.blocking_cnt = 0;
+    ruby_single_main_ractor = th->ractor;
+    th->ractor->status_ = ractor_created;
+
+    rb_ractor_living_threads_init(th->ractor);
+    rb_ractor_living_threads_insert(th->ractor, th);
+
+    VM_ASSERT(vm->ractor.blocking_cnt == 0);
+    VM_ASSERT(vm->ractor.cnt == 1);
+}
+#endif
+
 void rb_gvl_init(rb_global_vm_lock_t *gvl);
 
 void
diff --git a/ractor_core.h b/ractor_core.h
index 4451e06..0aa66f6 100644
--- a/ractor_core.h
+++ b/ractor_core.h
@@ -182,6 +182,7 @@ void rb_ractor_terminate_interrupt_main_thread(rb_ractor_t *r); https://github.com/ruby/ruby/blob/trunk/ractor_core.h#L182
 void rb_ractor_terminate_all(void);
 bool rb_ractor_main_p_(void);
 void rb_ractor_finish_marking(void);
+void rb_ractor_atfork(rb_vm_t *vm, rb_thread_t *th);
 
 RUBY_SYMBOL_EXPORT_BEGIN
 bool rb_ractor_shareable_p_continue(VALUE obj);
diff --git a/thread.c b/thread.c
index a7cd6e4..22b77b7 100644
--- a/thread.c
+++ b/thread.c
@@ -4719,6 +4719,7 @@ rb_clear_coverages(void) https://github.com/ruby/ruby/blob/trunk/thread.c#L4719
 }
 
 #if defined(HAVE_WORKING_FORK)
+
 static void
 rb_thread_atfork_internal(rb_thread_t *th, void (*atfork)(rb_thread_t *, const rb_thread_t *))
 {
@@ -4741,11 +4742,7 @@ rb_thread_atfork_internal(rb_thread_t *th, void (*atfork)(rb_thread_t *, const r https://github.com/ruby/ruby/blob/trunk/thread.c#L4742
     }
     rb_vm_living_threads_init(vm);
 
-    // threads
-    vm->ractor.cnt = 0;
-    rb_ractor_living_threads_init(th->ractor);
-    rb_ractor_living_threads_insert(th->ractor, th);
-
+    rb_ractor_atfork(vm, th);
 
     /* may be held by MJIT threads in parent */
     rb_native_mutex_initialize(&vm->waitpid_lock);
@@ -4758,6 +4755,7 @@ rb_thread_atfork_internal(rb_thread_t *th, void (*atfork)(rb_thread_t *, const r https://github.com/ruby/ruby/blob/trunk/thread.c#L4755
     rb_ractor_sleeper_threads_clear(th->ractor);
     rb_clear_coverages();
 
+    VM_ASSERT(vm->ractor.blocking_cnt == 0);
     VM_ASSERT(vm->ractor.cnt == 1);
 }
 
-- 
cgit v0.10.2


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

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