@@ -2297,13 +2297,27 @@ impl Child {
2297
2297
/// considered undesirable. Note that returning from `main` also calls `exit`, so making `exit` an
2298
2298
/// unsafe operation is not an option.)
2299
2299
///
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
2301
2316
///
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`.
2307
2321
///
2308
2322
/// Therefore, it is undefined behavior to have two concurrent threads perform the following
2309
2323
/// without synchronization:
@@ -2324,21 +2338,6 @@ impl Child {
2324
2338
/// - [GNU C library Bugzilla](https://sourceware.org/bugzilla/show_bug.cgi?id=31997)
2325
2339
///
2326
2340
/// [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
- /// ```
2342
2341
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2343
2342
#[ cfg_attr( not( test) , rustc_diagnostic_item = "process_exit" ) ]
2344
2343
pub fn exit ( code : i32 ) -> ! {
0 commit comments