You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Proxying] Cancel proxied work when the worker thread dies (#18741)
Update the synchronous proxying APIs to return 0 when attempting to proxy to a
thread that has already exited or has been canceled or exits or is canceled
before the proxied work is completed.
To implement cancellation, add an optional `cancel` function pointer to the
tasks queued in `em_task_queue`s, which are the internal thread-specific queues
used in the implementation of `em_proxying_queue`. This `cancel` function
pointer is not controllable directly by users of the API, but is rather used
internally to ensure that synchronous waiters are notified when the thread they
are waiting on dies. This mechanism will scale to other forms of cancellation
notification in the future. For example, it could be used to reject a promise
associated with the proxied work.
When a thread dies, it runs the cancellation handlers for each task in its
mailbox. Those tasks each carry a pointer to some task queue owned by a proxying
queue, so their cancellation handlers in turn run the cancellation handlers for
all the tasks in those pointed-to queues.
Task queue cancellation handlers do not handle the case of proxied work that has
been started but not finished when the worker thread dies because that work has
already been removed from the task queues. To cancel in-progress work as well,
update the implementation of synchronous proxying to place `em_proxying_ctx`
objects associated with active work in a thread-local doubly linked list that is
traversed by a registered thread specific data destructor. The destructor takes
care of canceling the active work.
Implements the design sketched out in #18631.
0 commit comments