Skip to content

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

Closed
bavulapati wants to merge 1 commit into
queue-lockingfrom
queue-ownership
Closed

bavulapati wants to merge 1 commit into
queue-lockingfrom
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.

Stacked on #105.

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 if 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.
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.

1 participant