Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit exit from main #15299

Conversation

ysbaddaden
Copy link
Contributor

@ysbaddaden ysbaddaden commented Dec 20, 2024

In a MT environment such as proposed in crystal-lang/rfcs#2, the main thread's fiber may be resumed by any thread, and it may return which would terminate the program... but it might return from another thread that the process' main thread, which may be unexpected by the OS.

This patch instead explicitly exits from main and wmain.

For backward compatibility reasons (win32 wmain and wasi __main_argc_argv both call main andand are documented to do so), the default main still returns, but is being replaced for UNIX targets by one that exits.

Maybe the OS actual entrypoint could merely call Crystal.main instead of main and explicitely exit (there wouldn't be a global main except for UNIX), but this is out of scope for this PR.

In a MT environment the main thread's fiber may be resumed by any
thread, which may terminate the program, and would return from another
thread that the process' main thread, which may be

This patches instead explicitly exits from `main` and `wmain`.

For backward compatibility reason (win32's `wmain` and wasi's
`__main_argc_argv` call `main`), the default `main` still returns, and
is replaced for UNIX targets.
@ysbaddaden ysbaddaden self-assigned this Dec 20, 2024
@straight-shoota straight-shoota added this to the 1.15.0 milestone Dec 20, 2024
@straight-shoota straight-shoota merged commit c38f4df into crystal-lang:master Dec 25, 2024
69 checks passed
@ysbaddaden ysbaddaden deleted the refactor/explicit-exit-from-main branch December 29, 2024 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Approved
Development

Successfully merging this pull request may close these issues.

2 participants