Skip to content

Commit

Permalink
Rollup merge of rust-lang#52759 - stjepang:impl-send-sync-for-joinhan…
Browse files Browse the repository at this point in the history
…dle, r=TimNN

Impl Send & Sync for JoinHandle

This is just a cosmetic change - it slightly relaxes and clarifies the public API without effectively promising any new guarantees.

Currently we have [these auto trait implementations](https://doc.rust-lang.org/nightly/std/thread/struct.JoinHandle.html#synthetic-implementations):

```rust
impl<T: Send> Send for JoinHandle<T> {}
impl<T: Sync> Sync for JoinHandle<T> {}
```

Bound `T: Send` doesn't make much sense because `JoinHandle<T>` can be created only when `T: Send`. Note that [`JoinHandle::<T>::join`](https://doc.rust-lang.org/nightly/std/thread/struct.JoinHandle.html#method.join) doesn't require `T: Send` so why should the `Send` impl?

And the `Sync` impl doesn't need `T: Sync` because `JoinHandle<T>` cannot even share `T` - it can only send it to the thread that calls `join`.
  • Loading branch information
kennytm authored Jul 28, 2018
2 parents b584c32 + 688db1d commit b326319
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/libstd/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,11 @@ impl<T> JoinInner<T> {
#[stable(feature = "rust1", since = "1.0.0")]
pub struct JoinHandle<T>(JoinInner<T>);

#[stable(feature = "joinhandle_impl_send_sync", since = "1.29.0")]
unsafe impl<T> Send for JoinHandle<T> {}
#[stable(feature = "joinhandle_impl_send_sync", since = "1.29.0")]
unsafe impl<T> Sync for JoinHandle<T> {}

impl<T> JoinHandle<T> {
/// Extracts a handle to the underlying thread.
///
Expand Down

0 comments on commit b326319

Please sign in to comment.