Skip to content

Commit 21dd88f

Browse files
committed
exit: explain our expectations for the exit handlers registered in a Rust program
1 parent 717aec0 commit 21dd88f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

library/std/src/process.rs

+9
Original file line numberDiff line numberDiff line change
@@ -2296,6 +2296,15 @@ impl Child {
22962296
/// }
22972297
/// ```
22982298
///
2299+
/// In its current implementation, this function will execute exit handlers registered with `atexit`
2300+
/// as well as other platform-specific exit handlers (e.g. `fini` sections of ELF shared objects).
2301+
/// This means that Rust requires that all exit handlers are safe to execute at any time. In
2302+
/// particular, if an exit handler cleans up some state that might be concurrently accessed by other
2303+
/// threads, it is required that the exit handler performs suitable synchronization with those
2304+
/// threads. (The alternative to this requirement would be to not run exit handlers at all, which is
2305+
/// considered undesirable. Note that returning from `main` also calls `exit`, so making `exit` an
2306+
/// unsafe operation is not an option.)
2307+
///
22992308
/// ## Platform-specific behavior
23002309
///
23012310
/// **Unix**: On Unix-like platforms, it is unlikely that all 32 bits of `exit`

0 commit comments

Comments
 (0)