Enable emscripten_futex API for Wasm Workers#26325
Enable emscripten_futex API for Wasm Workers#26325sbc100 merged 1 commit intoemscripten-core:mainfrom
Conversation
73a4b15 to
3cbc701
Compare
3cbc701 to
dae5acb
Compare
|
Can you also take a look at #26309 which this change depends on ? |
dae5acb to
8351a68
Compare
Maybe a better approach would be to implement |
I think they overhead is more about being able to run on the main thread.
So at the very least we need to have |
8351a68 to
326873c
Compare
This involves also including `emscripten_thread_state.S` which provides APIs such as `emscripten_is_main_runtime_thread` and emscripten_is_main_browser_thread` which now also work in Wasm Workers. There is a minor code size hit here of ~80 bytes, but I think its worth it to have these low level APIs available everywhere.
326873c to
b2e07e5
Compare
|
OK, I jumped through some hoops to ensure that the cost of tracking the tread state is only payed for programs that use these APIs. |
| .functype _emscripten_thread_supports_atomics_wait () -> (i32) | ||
| #if WASM_WORKERS_ONLY | ||
| call lazy_init_thread_state | ||
| #endif |
There was a problem hiding this comment.
I wonder if there might be a solution that would use the __postset construct, with a
init_thread_state__postset: '__do_set_thread_state()',
emscripten_futex_wait__deps: ['init_thread_state'],
emscripten_futex_wake__deps: ['init_thread_state'],
emscripten_is_main_runtime_thread__deps: ['init_thread_state'],
emscripten_is_main_browser_thread__deps: ['init_thread_state'],
This way we would avoid the complexity of the lazy init, but still, only emit the thread state initialization if any of the functions needing it would be called?
There was a problem hiding this comment.
That sounds like a good idea if it could be made to work.
Its tricky because those function are not JS function so they can't currently have __deps entries like that.
But yes, it would be good find a solution that was dependency graph based rather than based on a runtime flag.
There was a problem hiding this comment.
Also this "thread state" is just a handful of wasm globals so I'm hoping maybe the cost if very marginal for real programs.
This involves also including
emscripten_thread_state.Swhich providesAPIs such as
emscripten_is_main_runtime_threadandemscripten_is_main_browser_thread` which now also work in Wasm Workers.
There is a minor code size hit here of ~80 bytes, but I think its
worth it to have these low level APIs available everywhere.
Depends on: #26309
Fixes: #26314