Commit 5b23834e

5b23834e3b06Merged

Ori Pekelman <[email protected]> · 5 months ago · 5 files · ~5 modified

Description

Ractor: free per-thread string heap on exit; retain control structs (valgrind-clean)

valgrind memcheck (now available on the dev box) surfaced two leaks that the sanitizers didn't flag as errors:

  • Strings allocated on a Ractor thread's heap leaked on exit: sp_gc_thread_teardown freed the GC object heap but not sp_str_heap, which is static to the generated TU and so unreachable from lib/sp_gc.c. Add a sp_gc_str_teardown_hook the TU installs (sp_str_heap_free_all), invoked from sp_gc_thread_teardown -- mirrors the existing mark-globals / str-sweep hooks.

  • The sp_Ractor control struct + its queue buffers were "definitely lost": a detached worker thread plus a GC-untracked creator handle leave no safe mid-run free point. Rather than leak, link every Ractor into a process-lifetime registry at creation; it stays reachable and is reclaimed by the OS at exit (no refcount/join protocol needed for the milestone).

After this, both the milestone demo and the message-codec test are memcheck-clean (0 definitely/indirectly lost) and helgrind reports 0 data races, alongside the existing TSan/ASan/SPINEL_GC_VERIFY-clean results. Full suite still 896 pass / 0 fail / 0 error.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
5b23834e3b06
Parent
976fad6689ce

docs/RACTOR-RFC.mdmodifiedView file

@@ -145,9 +145,18 @@
145145 ## Verification
146146
147147 - The `__thread` storage-class conversion is behavior-neutral: the full
148- existing test suite (831 `.rb` tests) passes unchanged, single-threaded.
148+ existing test suite passes unchanged, single-threaded (896 pass / 0 fail /
149+ 0 error with the two Ractor tests; CI green on ubuntu-gcc/clang + macOS-clang).
149150 - `test/ractor_basic.rb` exercises `Ractor.new` / `receive` / `yield` /
150- `send` / `<<` / `take` end-to-end and prints `42` twice.
151+ `send` / `<<` / `take` end-to-end and prints `42` twice; `test/ractor_messages.rb`
152+ round-trips String / Symbol / poly+typed Array messages.
153+- Clean under `SPINEL_GC_VERIFY=1`, **ThreadSanitizer** and **AddressSanitizer**
154+ (run binaries under `setarch -R` for TSan on this aarch64 box), and **valgrind
155+ memcheck + helgrind** report 0 leaks / 0 data races. Each Ractor's private GC
156+ and string heaps are freed on thread exit (`sp_gc_thread_teardown` +
157+ `sp_gc_str_teardown_hook`); the `sp_Ractor` control structs are retained in a
158+ process-lifetime registry (a detached worker plus a GC-untracked handle have
159+ no safe mid-run free point) so they stay reachable rather than leaking.
151160 - The isolation rule rejects a block that captures a mutable outer local with
152161 `Ractor::IsolationError`.
153162