ctor cause `fatal runtime error: thread::set_current should only be called once per thread`
rust version
rustc 1.82.0-nightly (5aea14073 2024-08-20)
system
Debian GNU/Linux 10 (buster)
ctor version
0.2.8
Code
// src/bin/test.rs
fn main() {
}
#[ctor::ctor]
fn setup() {
println!("enter")
}
Output
enter
fatal runtime error: thread::set_current should only be called once per thread
Same issue occurred in my project after updating to Rust 1.81.0. I resolved it using the libc-print crate.
I'm seeing the same thing after updating to Rust 1.81.0
Unfortunately the builtin println is not safe to use in ctor or dtor -- libc_print is specifically designed for this: https://crates.io/crates/libc-print.
I'm seeing the same thing after updating to Rust 1.81.0.
I'm seeing the same thing after updating to Rust 1.81.0
Closing in favour of a new FAQ entry -- this can be improved for sure but it's a good starting point.
https://github.com/mmastrac/rust-ctor/wiki/FAQ:-Life%E2%80%90before-and-life%E2%80%90after-main