The Rust program below panics when it accesses stdout
in the atexit
handler.
extern crate libc;
extern "C" fn bye() {
println!("bye");
}
fn main() {
println!("hello");
unsafe { libc::atexit(bye) };
}
Output:
hello
thread '<main>' panicked at 'cannot access stdout during shutdown', ../src/libcore/option.rs:298
fatal runtime error: Could not unwind stack, error = 5
An unknown error occurred
It seems to me that this registration should run before our atexit
registration, so this line in the handler should run only after our custom handler. Thus it should not panic.
You're confusing libc::atexit
, which you call, and sys_common::at_exit
(in src/libstd/sys/common/mod.rs) which your link points to and which Rust calls during early cleanup.
Those are two different cleanup queues, and I wouldn't want to rely on them being executed in a specific order.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With