emscripten-core / emscripten-core/emscripten

emscripten_thread_sleep should try to use Atomics.wait instead of busy sleep

Open
#20,000 2 comments 2 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.