Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions site/source/docs/tools_reference/settings_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,22 @@ Default value: true
EXIT_RUNTIME
============

If 0, the runtime is not quit when main() completes (allowing code to
run afterwards, for example from the browser main event loop). atexit()s
are also not executed, and we can avoid including code for runtime shutdown,
like flushing the stdio streams.
Set this to 1 if you do want atexit()s or stdio streams to be flushed
on exit.
If 0, support for shutting down the runtime is not emitted into the build.
This means that the program is not quit when main() completes, but execution
will yield to the event loop of the JS environment, allowing event handlers
to run afterwards. If 0, C++ global destructors will not be emitted into the
build either, to save on code size. Calling exit() will throw an unwinding
exception, but will not shut down the runtime.

Set this to 1 if you do want to retain the ability to shut down the program.
If 1, then completing main() will by default call exit(), unless a refcount
keeps the runtime alive. Call emscripten_exit_with_live_runtime() to finish
main() while keeping the runtime alive. Calling exit() will shut down the
runtime, invoking atexit()s, and flushing stdio streams.
Copy link
Collaborator

@sbc100 sbc100 Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think calling exit() won't do this while the refcount is non-zero.

If you want to override the refcount you would need to call emscripten_force_exit().

Also, maybe mention emscripten_runtime_keepalive_push() alongside emscripten_exit_with_live_runtime() which is basically the same thing but without the unwind.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do have docs for emscripten_force_exit and emscripten_exit_with_live_runtime so maybe just say something like See docs for ... rather than duplicating?

This setting is controlled automatically in STANDALONE_WASM mode:

- For a command (has a main function) this is always 1
- For a reactor (no a main function) this is always 0
- For a reactor (no main function) this is always 0

Default value: false

Expand Down
20 changes: 13 additions & 7 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,22 @@ var VERBOSE = false;
// [link]
var INVOKE_RUN = true;

// If 0, the runtime is not quit when main() completes (allowing code to
// run afterwards, for example from the browser main event loop). atexit()s
// are also not executed, and we can avoid including code for runtime shutdown,
// like flushing the stdio streams.
// Set this to 1 if you do want atexit()s or stdio streams to be flushed
// on exit.
// If 0, support for shutting down the runtime is not emitted into the build.
// This means that the program is not quit when main() completes, but execution
// will yield to the event loop of the JS environment, allowing event handlers
// to run afterwards. If 0, C++ global destructors will not be emitted into the
// build either, to save on code size. Calling exit() will throw an unwinding
// exception, but will not shut down the runtime.
//
// Set this to 1 if you do want to retain the ability to shut down the program.
// If 1, then completing main() will by default call exit(), unless a refcount
// keeps the runtime alive. Call emscripten_exit_with_live_runtime() to finish
// main() while keeping the runtime alive. Calling exit() will shut down the
// runtime, invoking atexit()s, and flushing stdio streams.
// This setting is controlled automatically in STANDALONE_WASM mode:
//
// - For a command (has a main function) this is always 1
// - For a reactor (no a main function) this is always 0
// - For a reactor (no main function) this is always 0
//
// [link]
var EXIT_RUNTIME = false;
Expand Down
Loading