emscripten-core / emscripten-core/emscripten
Program hangs joining a thread with live runtime
- 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
Assessment
This issue has not been assessed yet.