Skip to content

Commit 30ec1f0

Browse files
authored
Rollup merge of #84083 - ltratt:threadid_doc_tweak, r=dtolnay
Clarify the guarantees that ThreadId does and doesn't make. The existing documentation does not spell out whether `ThreadId`s are unique during the lifetime of a thread or of a process. I had to examine the source code to realise (pleasingly!) that they're unique for the lifetime of a process. That seems worth documenting clearly, as it's a strong guarantee. Examining the way `ThreadId`s are created also made me realise that the `as_u64` method on `ThreadId` could be a trap for the unwary on those platforms where the platform's notion of a thread identifier is also a 64 bit integer (particularly if they happen to use a similar identifier scheme to `ThreadId`). I therefore think it's worth being even clearer that there's no relationship between the two.
2 parents c145692 + d66a9e1 commit 30ec1f0

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

library/std/src/thread/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -972,10 +972,13 @@ pub fn park_timeout(dur: Duration) {
972972

973973
/// A unique identifier for a running thread.
974974
///
975-
/// A `ThreadId` is an opaque object that has a unique value for each thread
976-
/// that creates one. `ThreadId`s are not guaranteed to correspond to a thread's
977-
/// system-designated identifier. A `ThreadId` can be retrieved from the [`id`]
978-
/// method on a [`Thread`].
975+
/// A `ThreadId` is an opaque object that uniquely identifies each thread
976+
/// created during the lifetime of a process. `ThreadId`s are guaranteed not to
977+
/// be reused, even when a thread terminates. `ThreadId`s are under the control
978+
/// of Rust's standard library and there may not be any relationship between
979+
/// `ThreadId` and the underlying platform's notion of a thread identifier --
980+
/// the two concepts cannot, therefore, be used interchangeably. A `ThreadId`
981+
/// can be retrieved from the [`id`] method on a [`Thread`].
979982
///
980983
/// # Examples
981984
///

0 commit comments

Comments
 (0)