Skip to main content

Module exit_code

Module exit_code 

Source
Expand description

Process exit code handling

Stores the integer value returned from main ( -- Int ) so the C-level main function can read it after the scheduler joins all strands and return it as the process exit code.

§Lifetime

  • The user’s seq_main function calls patch_seq_set_exit_code with the top-of-stack Int just before its stack is freed.
  • The C main function calls patch_seq_get_exit_code after patch_seq_scheduler_run returns and uses the value as the process exit code.

§Concurrency

The exit code is a single atomic global. Only the main strand writes to it, and only after all spawned strands have finished (since scheduler_run joins all strands). The C main reads it after scheduler_run returns. There is no race.

Programs declaring main ( -- ) (void main) never call the setter, so the exit code remains 0 — matching the historical behavior.

Functions§

patch_seq_get_exit_code
Get the process exit code.
patch_seq_set_exit_code
Set the process exit code.