about summary refs log tree commit diff
path: root/library/std/src/thread/mod.rs
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2024-05-22 14:10:52 +0200
committerMara Bos <m-ou.se@m-ou.se>2024-11-19 18:54:20 +0100
commit7ac4c04731ecb6eedd63a1f899a0c6207679cbf9 (patch)
treedcd06bf0b8755044b9d975f0eda18e28c8cf82a0 /library/std/src/thread/mod.rs
parent145f9cf95de1fbde3fa11e98461310e0373253e6 (diff)
downloadrust-7ac4c04731ecb6eedd63a1f899a0c6207679cbf9.tar.gz
rust-7ac4c04731ecb6eedd63a1f899a0c6207679cbf9.zip
Add std::thread::add_spawn_hook.
Diffstat (limited to 'library/std/src/thread/mod.rs')
-rw-r--r--library/std/src/thread/mod.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs
index 227ee9d64f3..ee8d688398d 100644
--- a/library/std/src/thread/mod.rs
+++ b/library/std/src/thread/mod.rs
@@ -188,6 +188,11 @@ mod current;
 pub use current::current;
 pub(crate) use current::{current_id, drop_current, set_current, try_current};
 
+mod spawnhook;
+
+#[unstable(feature = "thread_spawn_hook", issue = "none")]
+pub use spawnhook::add_spawn_hook;
+
 ////////////////////////////////////////////////////////////////////////////////
 // Thread-local storage
 ////////////////////////////////////////////////////////////////////////////////
@@ -485,6 +490,9 @@ impl Builder {
             Some(name) => Thread::new(id, name.into()),
             None => Thread::new_unnamed(id),
         };
+
+        let hooks = spawnhook::run_spawn_hooks(&my_thread)?;
+
         let their_thread = my_thread.clone();
 
         let my_packet: Arc<Packet<'scope, T>> = Arc::new(Packet {
@@ -535,6 +543,9 @@ impl Builder {
             }
 
             crate::io::set_output_capture(output_capture);
+            for hook in hooks {
+                hook();
+            }
 
             let f = f.into_inner();
             let try_result = panic::catch_unwind(panic::AssertUnwindSafe(|| {