diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-01-01 22:49:47 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-01 22:49:47 +0100 |
| commit | 30ec1f0384338351902a22d9d0e7f867f142a1f6 (patch) | |
| tree | 69263856b3a327747fb6c4157124458ecf4abf02 | |
| parent | c145692254e86974941f2c92c643a23df0f13e82 (diff) | |
| parent | d66a9e16bae86863cfdbd033b49b672da34bdde1 (diff) | |
| download | rust-30ec1f0384338351902a22d9d0e7f867f142a1f6.tar.gz rust-30ec1f0384338351902a22d9d0e7f867f142a1f6.zip | |
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.
| -rw-r--r-- | library/std/src/thread/mod.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index bcf2ec06022..9f7f10d0d00 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -972,10 +972,13 @@ pub fn park_timeout(dur: Duration) { /// A unique identifier for a running thread. /// -/// A `ThreadId` is an opaque object that has a unique value for each thread -/// that creates one. `ThreadId`s are not guaranteed to correspond to a thread's -/// system-designated identifier. A `ThreadId` can be retrieved from the [`id`] -/// method on a [`Thread`]. +/// A `ThreadId` is an opaque object that uniquely identifies each thread +/// created during the lifetime of a process. `ThreadId`s are guaranteed not to +/// be reused, even when a thread terminates. `ThreadId`s are under the control +/// of Rust's standard library and there may not be any relationship between +/// `ThreadId` and the underlying platform's notion of a thread identifier -- +/// the two concepts cannot, therefore, be used interchangeably. A `ThreadId` +/// can be retrieved from the [`id`] method on a [`Thread`]. /// /// # Examples /// |
