-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Closed
Labels
Description
There is something wrong with the way Emscripten uses threads on Node.js. Looks like any usage prevents Node app from ever exiting.
Just tried the simplest example:
#include <thread>
#include <iostream>
int main() {
std::thread t([] {
std::cout << "Hello from another thread\n";
});
t.join();
return 0;
}
Compiled with:
> emcc temp.cc -o temp.js -pthread -s PTHREAD_POOL_SIZE=4
This results in:
> node --experimental-wasm-threads --experimental-wasm-bulk-memory temp
Hello from another thread
Pthread 0x705d10 exited.
[stuck here]
Looking at https://nodejs.org/api/worker_threads.html, I suspect Emscripten needs to call .unref()
to indicate that it's okay to exit as soon as reference is unreachable, but probably doesn't do that yet?