Skip to content

Commit

Permalink
Use a global lock for exit on unix.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachs18 authored Jun 17, 2024
1 parent 1138036 commit 9a30e1b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion library/std/src/sys/pal/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,13 @@ pub fn home_dir() -> Option<PathBuf> {
}

pub fn exit(code: i32) -> ! {
unsafe { libc::exit(code as c_int) }
use crate::sync::OnceLock;
// https://github.com/rust-lang/rust/issues/126600
// Ensure that only one Rust thread calls exit.
// Technically not enough to ensure soundness, since other code directly calling
// libc::exit will still race with this.
static EXIT_ONCE: OnceLock<!> = OnceLock::new();
*EXIT_ONCE.get_or_init(|| unsafe { libc::exit(code as c_int) })
}

pub fn getpid() -> u32 {
Expand Down

0 comments on commit 9a30e1b

Please sign in to comment.