You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
rt::atexit callbacks don't run after exit(0) call #28065
// FIXME: switch this to use atexit. Currently this// segfaults (the queue's memory is mysteriously gone), so// instead the cleanup is tied to the `std::rt` entry point.
The only way that at_exit_imp::cleanup is invoked is when the main thread either returns gracefully or panics gracefully so the Rust entry point can run the cleanup method, which clearly excludes when invoking process::exit.
Hm, I had forgotten about that comment. Regardless though there is no reason that this should fundamentally not be able to use atexit, it's just some implementation detail that needs to be worked out
The way the CRT on Windows handles atexit is it just has a table of all the atexit handlers, and when you call the CRT's exit it goes through and executes all the handlers and then calls ExitProcess (or TerminateProcess for windows store apps). Since Rust currently calls ExitProcess directly, that means using the libc atexit is useless since its handlers will never fire. However, it also means we can easily get rt::atexit to work with process::exit by just having process::exit call the rt::cleanup method (with some sort of synchronization to ensure it is only called once).
Hm, you know I had a feeling the test I added in #28069 would fail on Windows for a reason like that, I think we'll have to do something like that on Windows (call cleanup manually from process::exit)
Activity
alexcrichton commentedon Aug 28, 2015
I... thought we had an issue for this and did this previously, not sure what happened here!
retep998 commentedon Aug 28, 2015
To quote the source code
The only way that
at_exit_imp::cleanupis invoked is when the main thread either returns gracefully or panics gracefully so the Rust entry point can run the cleanup method, which clearly excludes when invokingprocess::exit.alexcrichton commentedon Aug 28, 2015
Hm, I had forgotten about that comment. Regardless though there is no reason that this should fundamentally not be able to use
atexit, it's just some implementation detail that needs to be worked outretep998 commentedon Aug 28, 2015
The way the CRT on Windows handles
atexitis it just has a table of all theatexithandlers, and when you call the CRT'sexitit goes through and executes all the handlers and then callsExitProcess(orTerminateProcessfor windows store apps). Since Rust currently callsExitProcessdirectly, that means using the libcatexitis useless since its handlers will never fire. However, it also means we can easily getrt::atexitto work withprocess::exitby just havingprocess::exitcall thert::cleanupmethod (with some sort of synchronization to ensure it is only called once).alexcrichton commentedon Aug 28, 2015
Hm, you know I had a feeling the test I added in #28069 would fail on Windows for a reason like that, I think we'll have to do something like that on Windows (call
cleanupmanually fromprocess::exit)Auto merge of #28069 - alexcrichton:rt-atexit, r=brson