Repository navigation
Fix toplevel static initializers - #959
Open
TimWhiting wants to merge 1 commit into
Open
TimWhiting wants to merge 1 commit into
TimWhiting wants to merge 1 commit into
Conversation
TimWhiting
marked this pull request as draft
October 14, 2026 14:19
TimWhiting
force-pushed
the
fix-static-initializers
branch
2 times, most recently
from
October 14, 2026 14:29
fe3cee1 to
6aeebab
Compare
TimWhiting
marked this pull request as ready for review
October 14, 2026 14:32
TimWhiting
force-pushed
the
fix-static-initializers
branch
from
October 14, 2026 14:48
6aeebab to
365d85c
Compare
A toplevel constant lives in a C static that every thread dups and drops, and Perceus refcounts are not atomic: two threads updating one count race, and the constant can be freed while still in use. `@init` now marks every block of a constant's graph stuck (`kk_box_mark_static`): dup and drop leave it unchanged and it is never freed, as for a compile-time static. Blocks that are already thread-shared stay atomically counted. `kk_box_mark_static` shares the traversal of `kk_box_mark_shared`, which now takes whether to make blocks stuck or thread-shared. test/cgen/static-thread-race: eight tasks dup and drop one toplevel list; without this it segfaults on every run (5 of 5, macOS arm64). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TimWhiting
force-pushed
the
fix-static-initializers
branch
from
October 27, 2026 12:44
365d85c to
0612dec
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Top level primitives and boxed values must be marked thread-shared in order for races not to happen with reference counting. Otherwise +2 -2 references can turn into +1 -2 and free a top level static value!