Skip to content

Commit c133e22

Browse files
committed
move new section into platform-specific behavior, as it is unix-specific
1 parent 7b5e847 commit c133e22

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

library/std/src/process.rs

+20-21
Original file line numberDiff line numberDiff line change
@@ -2297,13 +2297,27 @@ impl Child {
22972297
/// considered undesirable. Note that returning from `main` also calls `exit`, so making `exit` an
22982298
/// unsafe operation is not an option.)
22992299
///
2300-
/// ## Safe interop with C code
2300+
/// ## Platform-specific behavior
2301+
///
2302+
/// **Unix**: On Unix-like platforms, it is unlikely that all 32 bits of `exit`
2303+
/// will be visible to a parent process inspecting the exit code. On most
2304+
/// Unix-like platforms, only the eight least-significant bits are considered.
2305+
///
2306+
/// For example, the exit code for this example will be `0` on Linux, but `256`
2307+
/// on Windows:
2308+
///
2309+
/// ```no_run
2310+
/// use std::process;
2311+
///
2312+
/// process::exit(0x0100);
2313+
/// ```
2314+
///
2315+
/// ### Safe interop with C code
23012316
///
2302-
/// This function is safe to call as long as `exit` is only ever invoked from Rust. However, on some
2303-
/// platforms this function is implemented by calling the C function [`exit`][C-exit]. As of C23,
2304-
/// the C standard does not permit multiple threads to call `exit` concurrently. Rust mitigates this
2305-
/// with a lock, but if C code calls `exit`, that can still cause undefined behavior. Note that
2306-
/// returning from `main` is equivalent to calling `exit`.
2317+
/// On Unix, this function is currently implemented using the `exit` C function [`exit`][C-exit]. As
2318+
/// of C23, the C standard does not permit multiple threads to call `exit` concurrently. Rust
2319+
/// mitigates this with a lock, but if C code calls `exit`, that can still cause undefined behavior.
2320+
/// Note that returning from `main` is equivalent to calling `exit`.
23072321
///
23082322
/// Therefore, it is undefined behavior to have two concurrent threads perform the following
23092323
/// without synchronization:
@@ -2324,21 +2338,6 @@ impl Child {
23242338
/// - [GNU C library Bugzilla](https://sourceware.org/bugzilla/show_bug.cgi?id=31997)
23252339
///
23262340
/// [C-exit]: https://en.cppreference.com/w/c/program/exit
2327-
///
2328-
/// ## Platform-specific behavior
2329-
///
2330-
/// **Unix**: On Unix-like platforms, it is unlikely that all 32 bits of `exit`
2331-
/// will be visible to a parent process inspecting the exit code. On most
2332-
/// Unix-like platforms, only the eight least-significant bits are considered.
2333-
///
2334-
/// For example, the exit code for this example will be `0` on Linux, but `256`
2335-
/// on Windows:
2336-
///
2337-
/// ```no_run
2338-
/// use std::process;
2339-
///
2340-
/// process::exit(0x0100);
2341-
/// ```
23422341
#[stable(feature = "rust1", since = "1.0.0")]
23432342
#[cfg_attr(not(test), rustc_diagnostic_item = "process_exit")]
23442343
pub fn exit(code: i32) -> ! {

0 commit comments

Comments
 (0)