emscripten-core / emscripten-core/emscripten

Node.js pthread implementation shutting down before pthread prints.

Open
#25,215 33 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Consider the following test case:

`test.c`
```c
#include
#include
#include
#include

void* thread_main(void* param) {
printf("thread_main\n");
exit(0);
}

int main(int argc, char** argv) {
pthread_t thread;
pthread_create(&thread, 0, thread_main, NULL);
emscripten_exit_with_live_runtime();
}
```
`emcc test.c -o a.html -pthread -sEXIT_RUNTIME=1`

---------------

The main thread creates a pthread, and then yields out from `main()`, leaving the runtime alive on the main thread.

The pthread then does a print, and exits the whole program.

When run in `node`, this application prints nothing and quits (no `thread_main` printed).

When run in a browser, the printf does appear, but calling `exit(0)` does not shut down the runtime.

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.