emscripten-core / emscripten-core/emscripten
emscripten_thread_sleep should try to use Atomics.wait instead of busy sleep
Open
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Looking at the code here:
https://github.com/emscripten-core/emscripten/blob/main/system/lib/pthread/library_pthread_stub.c#L392-L401
I think it would be better to do something like this:
```js
const waitBuffer = new Int32Array(new WebAssembly.Memory({"shared":true,"initial":1,"maximum":1}).buffer);
function waitSleep(ms: number): boolean {
try {
Atomics.wait(waitBuffer, 0, 0, ms);
} catch (_) {
busySleep(ms);
}
}
```
Any thoughts?
Contributor guide
Assessment
This issue has not been assessed yet.