Skip to content

Give the queue an owner rather than a caller's storage - #108

Merged
bavulapati merged 1 commit into
mainfrom
queue-ownership
Aug 14, 2026
Merged

bavulapati merged 1 commit into
mainfrom
queue-ownership

Conversation

@bavulapati

Copy link
Copy Markdown
Contributor

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_uv and bare_queue_shutdown_thread retire 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.

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.
@bavulapati
bavulapati requested a review from a team August 14, 2026 13:11
@bavulapati
bavulapati merged commit f6108b3 into main Aug 14, 2026
11 checks passed
@bavulapati
bavulapati deleted the queue-ownership branch August 14, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants