-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Documented thread hooks on panics and errors of thread spawning functions. #149927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
d3e4f2b
a7185e9
8f0a1ce
d3a7384
9a7daa3
4e79475
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,8 +45,11 @@ use crate::{io, panicking}; | |
| /// | ||
| /// # Panics | ||
| /// | ||
| /// Panics if the OS fails to create a thread; use [`Builder::spawn`] | ||
| /// to recover from such errors. | ||
| /// Panics if the OS fails to create a thread; use [`Builder::spawn`] to recover | ||
| /// from such errors. | ||
| /// | ||
| /// Additionally, if hooks were added via [`add_spawn_hook`], they will still be | ||
|
||
| /// called in the parent thread, but the returned functions will not be executed. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
|
|
@@ -120,6 +123,7 @@ use crate::{io, panicking}; | |
| /// [`channels`]: crate::sync::mpsc | ||
| /// [`join`]: JoinHandle::join | ||
| /// [`Err`]: crate::result::Result::Err | ||
| /// [`add_spawn_hook`]: crate::thread::add_spawn_hook | ||
| #[stable(feature = "rust1", since = "1.0.0")] | ||
| #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces | ||
| pub fn spawn<F, T>(f: F) -> JoinHandle<T> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -193,7 +193,13 @@ impl<'scope, 'env> Scope<'scope, 'env> { | |
| /// Panics if the OS fails to create a thread; use [`Builder::spawn_scoped`] | ||
| /// to recover from such errors. | ||
| /// | ||
| /// like the free [`spawn`] function, if hooks were added via [`add_spawn_hook`], | ||
|
||
| /// they will still be called in the parent thread, but the returned functions will | ||
| /// not be executed. | ||
| /// | ||
| /// [`join`]: ScopedJoinHandle::join | ||
| /// [`add_spawn_hook`]: crate::thread::add_spawn_hook | ||
| /// [`spawn`]: crate::thread::spawn | ||
| #[stable(feature = "scoped_threads", since = "1.63.0")] | ||
| pub fn spawn<F, T>(&'scope self, f: F) -> ScopedJoinHandle<'scope, T> | ||
| where | ||
|
|
@@ -210,12 +216,18 @@ impl Builder { | |
| /// Unlike [`Scope::spawn`], this method yields an [`io::Result`] to | ||
| /// capture any failure to create the thread at the OS level. | ||
| /// | ||
| /// [`io::Result`]: crate::io::Result | ||
| /// Like [`Scope::spawn`], this method will still call the main thread functions | ||
| /// added by [`add_spawn_hook`] (unless [`Builder::no_hooks`] was called), | ||
| /// but won't execute the returned functions if thread creation fails at the | ||
| /// OS level. | ||
| /// | ||
| /// # Panics | ||
| /// | ||
| /// Panics if a thread name was set and it contained null bytes. | ||
| /// | ||
| /// Unlike with [`Scope::spawn`], if it panics for this reason, the hooks | ||
| /// added by [`add_spawn_hook`] will _not_ be called. | ||
|
||
| /// | ||
| /// # Example | ||
| /// | ||
| /// ``` | ||
|
|
@@ -251,6 +263,9 @@ impl Builder { | |
| /// a.push(4); | ||
| /// assert_eq!(x, a.len()); | ||
| /// ``` | ||
| /// | ||
| /// [`io::Result`]: crate::io::Result | ||
| /// [`add_spawn_hook`]: crate::thread::add_spawn_hook | ||
| #[stable(feature = "scoped_threads", since = "1.63.0")] | ||
| pub fn spawn_scoped<'scope, 'env, F, T>( | ||
| self, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thread::spawncallsBuilder::spawninternally, so this is misleading – it's just thatthread::spawndoesn't set a thread name and thus will never panic for this reason.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will rephrase.