about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2024-08-25 17:12:12 +0200
committerRalf Jung <post@ralfj.de>2024-08-25 17:46:26 +0200
commit21dd88f963f8047fa6a3d0492fc7dcf86f5e5f4d (patch)
tree1c850a17ca4f26435c98f157f4150cbb94a73022
parent717aec0f8eebdc5eb51756e5129dde15e8b25710 (diff)
downloadrust-21dd88f963f8047fa6a3d0492fc7dcf86f5e5f4d.tar.gz
rust-21dd88f963f8047fa6a3d0492fc7dcf86f5e5f4d.zip
exit: explain our expectations for the exit handlers registered in a Rust program
-rw-r--r--library/std/src/process.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/library/std/src/process.rs b/library/std/src/process.rs
index 9ffdebe1b6f..bbea27ebc10 100644
--- a/library/std/src/process.rs
+++ b/library/std/src/process.rs
@@ -2296,6 +2296,15 @@ impl Child {
 /// }
 /// ```
 ///
+/// In its current implementation, this function will execute exit handlers registered with `atexit`
+/// as well as other platform-specific exit handlers (e.g. `fini` sections of ELF shared objects).
+/// This means that Rust requires that all exit handlers are safe to execute at any time. In
+/// particular, if an exit handler cleans up some state that might be concurrently accessed by other
+/// threads, it is required that the exit handler performs suitable synchronization with those
+/// threads. (The alternative to this requirement would be to not run exit handlers at all, which is
+/// considered undesirable. Note that returning from `main` also calls `exit`, so making `exit` an
+/// unsafe operation is not an option.)
+///
 /// ## Platform-specific behavior
 ///
 /// **Unix**: On Unix-like platforms, it is unlikely that all 32 bits of `exit`