Repository navigation
Give the queue an owner rather than a caller's storage - #108
Merged
Merged
Conversation
The worklet touches its end of the queue after it has parked, so by the ownership invariants the queue belongs to the worklet - which means it cannot sit in the host's storage, since a host may destroy its worklet the moment it has signalled it. The queue is now heap allocated: created by the host, handed over at start, and freed by the worklet once its loop is done, or by the host when no worklet was ever started. Each end is retired separately, so the side that goes first stops the other reaching what it is about to free. Adds a test covering the two-thread lifetime, and ports the locking test onto the new API.
kasperisager
approved these changes
Aug 14, 2026
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.
The worklet closes its end of the queue after it has parked, so by the invariants the queue must be owned by the worklet - and therefore cannot live in
bare_worklet_t, which is the host's storage and may go away as soon as the host has signalled the worklet to be destroyed.So: heap allocated, created by the host, handed over at start, freed by the worklet thread when its loop is done, or by the host when no worklet was ever started.
bare_queue_shutdown_uvandbare_queue_shutdown_threadretire one end each, so whichever side goes first stops the other from reaching what it is about to free.Nothing consumes the queue on main yet, so this changes an unused primitive and can be reviewed on its own. It is the ownership half of #94; the transport swap follows.
Reopens #106, which GitHub closed automatically when #105's branch was deleted. Also ports #105's locking test onto the new API and adds a two-thread lifetime test.