emscripten-core / emscripten-core/emscripten

Program hangs joining a thread with live runtime

Open
#16,493 0 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

Compiling this test program:

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

_Atomic int alive = 0;

void* thread_main(void* arg) {
alive = 1;
emscripten_exit_with_live_runtime();
return NULL;
}

int main() {
pthread_t thread;
pthread_create(&thread, NULL, thread_main, NULL);
while (!alive) {}
// pthread_cancel(thread);
emscripten_console_log("joining");
pthread_join(thread, NULL);
emscripten_console_log("done");
}

```

with

```
emcc test.c -o test.js -pthread -sPROXY_TO_PTHREAD -sEXIT_RUNTIME
```

and running it results in a hang while trying to join the thread. Adding a `pthread_cancel` before the join fixes it, but ideally would not be necessary. (A related issue is that the program still hangs if you add the cancel but remove the loop waiting for the thread to be live).

This affects test_pthread_proxying.c and test_pthread_proxying_cpp.cpp in #16468.

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.