diff options
| author | Peter Zhu <peter@peterzhu.ca> | 2025-08-26 15:42:41 -0400 |
|---|---|---|
| committer | Peter Zhu <peter@peterzhu.ca> | 2025-08-27 09:26:52 -0400 |
| commit | 8935cf98e5e6b1b94ffcb6ab46c83339487f5de0 (patch) | |
| tree | a20bdd6a684c89bfa8cba395f9b81a7522f3f98f | |
| parent | d2ef901f6cf86b3cd172782e2c629be162c99b72 (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.c | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -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)" : ""); |
