Skip to content

Commit 07ca948

Browse files
committed
exit: document interaction with C
1 parent a6434ef commit 07ca948

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

library/std/src/process.rs

+11
Original file line numberDiff line numberDiff line change
@@ -2294,6 +2294,17 @@ impl Child {
22942294
/// considered undesirable. Note that returning from `main` also calls `exit`, so making `exit` an
22952295
/// unsafe operation is not an option.)
22962296
///
2297+
/// ## Safe interop with C code
2298+
///
2299+
/// This function is safe to call as long as `exit` is only ever invoked from Rust. However, the C
2300+
/// standard does not permit multiple threads to call `exit` concurrently. Rust mitigates this with
2301+
/// a lock, but if C code calls `exit`, that can still cause undefined behavior. Note that returning
2302+
/// from `main` is equivalent to calling `exit`.
2303+
/// Therefore, it is undefeined behavior to have two concurrent threads perform the following
2304+
/// without synchronization:
2305+
/// - One thread calls Rust's `exit` function or returns from Rust's `main` function
2306+
/// - Another thread calls the C function `exit` or `quick_exit`, or returns from C's `main` function
2307+
///
22972308
/// ## Platform-specific behavior
22982309
///
22992310
/// **Unix**: On Unix-like platforms, it is unlikely that all 32 bits of `exit`

0 commit comments

Comments
 (0)