Gate reader discovery on cped_slot rather than undefined_addr - #403
Open
szegedi wants to merge 1 commit into
Open
Gate reader discovery on cped_slot rather than undefined_addr#403szegedi wants to merge 1 commit into
szegedi wants to merge 1 commit into
Conversation
Overall package sizeSelf size: 2.55 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | pprof-format | 2.3.1 | 504.33 kB | 504.33 kB | | source-map | 0.8.0 | 185.66 kB | 185.66 kB | | node-gyp-build | 4.8.4 | 13.86 kB | 13.86 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
|
szegedi
force-pushed
the
szegedi/thread-ctx-liveness
branch
from
August 28, 2026 12:07
3aab0d0 to
5b03b0e
Compare
szegedi
marked this pull request as ready for review
August 28, 2026 13:39
szegedi
requested review from
IlyasShabi,
nsavoire and
r1viollet
as code owners
August 28, 2026 13:39
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.
Makes
cped_slotthe field that the reader checks before it dereferences anything, and orders the writes to the thread local structure around it so it's written last on construction and cleared first on destruction.I'm in the process of writing an OTEP specification for the Node.js thread context protocol, so I'm ironing out some wrinkles I'm coming across with observable ordering of writes etc.
Why
cped_slotrather thanundefined_addrOur initial recommendation was to check
undefined_addrnot being zero for this, but it was actually serving two purposes: the value a reader compares against to detect "no context attached", and the liveness flag.I decided to instead use
cped_slotfor the liveness, for the following reasons:cped_slot != 0says "there is a slot to read", andundefined_addr != 0says "someone initialized this struct at some point".cped_slotremains null because that V8 has no CPED butundefined_addris set to non-zero. (We keep usingundefined_addr != 0as our internal "someone initialized this struct" signal, though.)The ordering
This really started out as an a-ha moment of "if undefined_addr is used by the reader as a gate, then I must make sure its initialization order is guaranteed", which then led me to "wait, why are we using undefined_addr and not cped_slot for this?".
And to boot, the order for
undefined_addrgate was actually wrong, as it was cleared last so it'd still be nonzero in front of other already-cleared fields and the reader can stop the thread while this is happening and observe the inconsistency. This was harmless in practice only because the cleared fields are null and cross-process reads of address 0 fail, so… safety by accident.Both stores are now
volatilebehind anatomic_signal_fenceand ordered to happen correctly.