emscripten-core / emscripten-core/emscripten

Missing API for the inverse of `emscripten_exit_with_live_runtime` when running in a pthread.

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

Its tempting to think that `emscripten_force_exit` is the inverse of `emscripten_exit_with_live_runtime` but that has the effect of bringing down the entire program.

Perhaps `pthread_exit()`, but that has two issues:

1. in honors the current keep-alive state of the calling thread
2. there is no such API in C++ threads.

See https://github.com/emscripten-core/emscripten/pull/16468 for an example of when this kind of API might be useful.

Two possible ways to add this API:

1. `emscripten_keep_alive_cancel()` (just rests the keep-alive state such that the thread will exit when it never returns to the even loop)
2. `emscripten_pthread_force_exit()` (resets the keep-alive state, but also unwinds the current stack).
3. expose `emscripten_keepalive_push()` and `emscripten_keepalive_pop()` that already exist internally?

In theory (1) is more valuable because it can be combined with the existing `emscripten_unwind_to_js_event_loop` to form that later, and could also be useful on the main thread.

Other possible names of `emscripten_keep_alive_cancel()`? `emscripten_allow_runtime_exit`?

Overall I think maybe `emscripten_keepalive_push()` and `emscripten_keepalive_pop()` are the most useful... although they still don't provide the big hammer of `force_exit`...

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.