Skip to content

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

@hoodmane

Description

@hoodmane

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:

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions