Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worklet termination #10169

Open
daxpedda opened this issue Feb 28, 2024 · 2 comments
Open

Worklet termination #10169

daxpedda opened this issue Feb 28, 2024 · 2 comments
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: worklets

Comments

@daxpedda
Copy link

What problem are you trying to solve?

A way to clean up multi-threaded Wasm resources when a worklet is garbage collected or otherwise finished/closed.

One way to currently do this with dedicated workers:

  • Parent Thread: Wait for a pre-determined memory location to be notified with Atomics.waitAsync().
  • Child Thread: When shutdown is desirable clean up Wasm thread resources.
  • Child Thread: Notify the pre-determined memory location with Atomics.notify().
  • Child Thread: Indefinitely block with Atomics.wait().
  • Parent Thread: Woken up by Atomics.notify(), call Worker.terminate() to clean up the worker.

Unfortunately this can't be done in worklets because they can't block, therefor there is no way to ensure that Wasm resources aren't being accessed.

What solutions exist today?

The best alternative is to invalidate the Wasm module and making any call to it throw, which doesn't solve the problem but at least prevents unsoundness.

How would you solve it?

A way to terminate worklets, like Worker.terminate() and an event that is triggered when the worklet closes. Alternatively only an event if worklets can be properly garbage collected even with a Wasm module.

I'm unsure how FinalizationRegistry could be used here instead of the event.

Anything else?

This is coming from WebAudio/web-audio-api#2568.

@daxpedda daxpedda added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest labels Feb 28, 2024
@annevk
Copy link
Member

annevk commented Mar 4, 2024

Somewhat related: #10136.

@annevk
Copy link
Member

annevk commented Mar 4, 2024

cc @padenot @hoch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: worklets
Development

No branches or pull requests

2 participants