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
## Verification- The `__thread` storage-class conversion is behavior-neutral: the full existing test suite (831 `.rb` tests) passes unchanged, single-threaded. existing test suite passes unchanged, single-threaded (896 pass / 0 fail / 0 error with the two Ractor tests; CI green on ubuntu-gcc/clang + macOS-clang).- `test/ractor_basic.rb` exercises `Ractor.new` / `receive` / `yield` / `send` / `<<` / `take` end-to-end and prints `42` twice. `send` / `<<` / `take` end-to-end and prints `42` twice; `test/ractor_messages.rb` round-trips String / Symbol / poly+typed Array messages.- Clean under `SPINEL_GC_VERIFY=1`, **ThreadSanitizer** and **AddressSanitizer** (run binaries under `setarch -R` for TSan on this aarch64 box), and **valgrind memcheck + helgrind** report 0 leaks / 0 data races. Each Ractor's private GC and string heaps are freed on thread exit (`sp_gc_thread_teardown` + `sp_gc_str_teardown_hook`); the `sp_Ractor` control structs are retained in a process-lifetime registry (a detached worker plus a GC-untracked handle have no safe mid-run free point) so they stay reachable rather than leaking.- The isolation rule rejects a block that captures a mutable outer local with `Ractor::IsolationError`.lib/sp_gc.cmodifiedView file
Loading diff…
lib/sp_gc.hmodifiedView file
Loading diff…
lib/sp_ractor.cmodifiedView file
Loading diff…
lib/sp_runtime.hmodifiedView file
Loading diff…