summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2025-08-26 15:42:41 -0400
committerPeter Zhu <peter@peterzhu.ca>2025-08-27 09:26:52 -0400
commit8935cf98e5e6b1b94ffcb6ab46c83339487f5de0 (patch)
treea20bdd6a684c89bfa8cba395f9b81a7522f3f98f
parentd2ef901f6cf86b3cd172782e2c629be162c99b72 (diff)
Fix malloc_gc_disabled in Ractor lock
We should disable GC for malloc for the current Ractor instead of the locked Ractor because it's the current Ractor that could run code that mallocs.
-rw-r--r--ractor.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/ractor.c b/ractor.c
index 57c9c4178f..4322bf1246 100644
--- a/ractor.c
+++ b/ractor.c
@@ -71,7 +71,11 @@ ractor_lock(rb_ractor_t *r, const char *file, int line)
ASSERT_ractor_unlocking(r);
rb_native_mutex_lock(&r->sync.lock);
- r->malloc_gc_disabled = true;
+
+ if (rb_current_execution_context(false)) {
+ VM_ASSERT(!GET_RACTOR()->malloc_gc_disabled);
+ GET_RACTOR()->malloc_gc_disabled = true;
+ }
#if RACTOR_CHECK_MODE > 0
if (rb_current_execution_context(false) != NULL) {
@@ -101,9 +105,11 @@ ractor_unlock(rb_ractor_t *r, const char *file, int line)
r->sync.locked_by = Qnil;
#endif
- VM_ASSERT(r->malloc_gc_disabled);
+ if (rb_current_execution_context(false)) {
+ VM_ASSERT(GET_RACTOR()->malloc_gc_disabled);
+ GET_RACTOR()->malloc_gc_disabled = false;
+ }
- r->malloc_gc_disabled = false;
rb_native_mutex_unlock(&r->sync.lock);
RUBY_DEBUG_LOG2(file, line, "r:%u%s", r->pub.id, rb_current_ractor_raw(false) == r ? " (self)" : "");