Skip to content

Usage of pthread in a Node.js app never lets it exit #12801

Description

@RReverser

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions