exit: explain our expectations for the exit handlers registered in a … · patricklam/verify-rust-std@b392703 (original) (raw)

Original file line number Diff line number Diff line change
@@ -2296,6 +2296,15 @@ impl Child {
2296 2296 /// }
2297 2297 /// ```
2298 2298 ///
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 +///
2299 2308 /// ## Platform-specific behavior
2300 2309 ///
2301 2310 /// **Unix**: On Unix-like platforms, it is unlikely that all 32 bits of `exit`