-
Notifications
You must be signed in to change notification settings - Fork 47
[Push|Pop]ErrorScope thread local error stacks #211
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
Comments
(Mostly my own thoughts but some from @lokokung @cwfitzgerald @rajveermalviya and old ideas from the JS API standardization) The current proposal for JS multithreading would have error scope stacks be thread-local. It's unlikely we'd want to make them racy, as this introduces major threading hazards to the JS API, and JS usually doesn't like those (I think the web platform currently has none - they're in JavaScript itself via SharedArrayBuffer - though the proposal does add another hazard to GPUBuffer mapping). If we went forward with that, then the model for WASM would have to be the same. Then in order to match that in native, we'd need to make the error scope stack thread local. Some contexts will not like this, e.g. bindings from languages that have green threads. It could still be the default, if we add a way for language bindings to cover it up. For example:
Maybe we could turn the thread-locality on/off in a global way (in requestDevice). It would be required to be on in initial WASM implementations (because that's all we can do with the JS API now) but then maybe allow turning it off later. If we can find a way to make it somewhat reasonable for error scope stacks to be non-thread-local but still usable in multithreaded native code (see "forking" below) then maybe this could work. We do still have the opportunity to change the proposal for multithreading in JS. We might have the opportunity to remove the "mistake" of global error scope state when you're using multithreading. Ideas (a grab bag, not a list of alternatives):
This reminds me there's been interest in faking multithreaded webgpu.h over single-threaded WebGPU by proxying WebGPU work to one thread: emscripten-core/emscripten#19645 |
webgpu.h meeting partial resolution:
|
Posting some old minutes because this issue is complicated and I need them to be accessible. (I wasn't posting full minutes back then for some reason.) 2023-08-10:
2023-08-17:
|
Dec 9 meeting:
|
Just to clarify the notes from above, I believe that the decision was Yes, do TLS for push/pop error stacks, and No, don't do error sinks for now. The notes in the comment above were all pertaining to error sinks, not TLS. |
Came up in a discussion with Kai today, but main question is how we intend to deal with error scopes in a multithread environment. The current model could race when an unrelated error on thread 1 is caught in a
popErrorScope
on thread 2.The simplest solution for now is a thread-local error stack, however, there are still some open questions / discussion points especially for other language bindings...
[Push|Pop]ErrorScope
, and instead expose something different so that we could be aligned with how the native version would work? Kai also mentioned that while the thread-local solution should work for JS, that it may be possible for some Rust runtimes on top of WASM to do something similar to the point above and run into the same issue.The text was updated successfully, but these errors were encountered: