Skip to content

thread can't spawn synchronously even with PTHREAD_POOL_SIZE=4 #15868

Description

@bakkot

This is with emcc version

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.0.2-git
clang version 14.0.0 (https://github.com/llvm/llvm-project.git 1a929525e86a20d0b3455a400d0dbed40b325a13)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /usr/local/opt/emscripten/libexec/llvm/bin

Here's a program:

#include <stdio.h>

#include <atomic>
#include <thread>

int main() {
  printf("hi\n");

  std::atomic<bool> done(false);
  std::thread t([&] {
    printf("other thread\n");
    done = true;
  });
  while (!done) {
    std::this_thread::yield();
  }
  t.join();
  return 0;
}

If built with

emcc main.cc -s EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=4 -s EXPORTED_FUNCTIONS=_main -o main.js

and run with node main.js, it will print hi then peg a core forever and never print other thread.

Built with g++ it will reach other thread and then exit.

The docs imply that setting -s PTHREAD_POOL_SIZE=4 should be sufficient to ensure at least one thread can be created on demand, but that does not seem to be the case. Is there any way to get this working?

(This case is reduced from a real example in Z3.)

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