[Proxying] Cancel proxied work when the worker thread dies - #18741
Conversation
|
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
|
The failing wasm2js test should be fixed by WebAssembly/binaryen#5489. |
741aafa to
b9fb8c0
Compare
sbc100
left a comment
There was a problem hiding this comment.
Do for each task we proxy we actually now create two tasks? (i.e. the user's work in the queue they specify, and then a special notification task which lives in the mailbox of the target thread?)
In the worst case, yes. However, if there is already a pending notification task in the mailbox of the target thread, then we don't create another one of those. |
sbc100
left a comment
There was a problem hiding this comment.
I can't say I've read an understood the entire change, especially the different tests cases. But I think this is great direction and the test coverage looks thorough.
|
Is |
|
I think the test failure on wasm64 is new flake that I recently added. |
yes, but I think/hope its only flaky on wasm64 |
|
That same test was failing |
54d2274 to
d13a814
Compare
d13a814 to
1301f0e
Compare
579f55d to
73023ce
Compare
1301f0e to
c7918e5
Compare
73023ce to
6ba6e6d
Compare
5223090 to
e0abb19
Compare
2f288d3 to
bc9b5ad
Compare
e0abb19 to
09a3df8
Compare
09a3df8 to
8b4eb90
Compare
|
Is this change good to go now? |
|
Yes. Since it got smaller since you last approved it, I was just going to land it as soon as the tests pass. |
|
Is it safe to land despite the test_minimal_runtime_code_size_random_printf_wasm failure? |
|
I just pushed a rebase of the expectations. If you rebase again you should be good. |
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.
8b4eb90 to
ea71ab3
Compare
…n-core#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 emscripten-core#18631.
…n-core#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 emscripten-core#18631.

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
cancelfunction pointer to thetasks queued in
em_task_queues, which are the internal thread-specific queuesused in the implementation of
em_proxying_queue. Thiscancelfunctionpointer 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_ctxobjects 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.