diff options
| author | kennytm <kennytm@gmail.com> | 2018-07-28 16:24:59 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-07-28 16:24:59 +0800 |
| commit | b326319f156dc1aea0b3389eeee4e8ef1b073c2a (patch) | |
| tree | b75c7d94f9f277068a4b7787cdb1b8cdeb9cc5f6 /src/libstd/thread | |
| parent | b584c3227d311f591d05ad442c08811884e99f1b (diff) | |
| parent | 688db1df80b9754c28b79abb141e381861402fca (diff) | |
| download | rust-b326319f156dc1aea0b3389eeee4e8ef1b073c2a.tar.gz rust-b326319f156dc1aea0b3389eeee4e8ef1b073c2a.zip | |
Rollup merge of #52759 - stjepang:impl-send-sync-for-joinhandle, 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`.
Diffstat (limited to 'src/libstd/thread')
| -rw-r--r-- | src/libstd/thread/mod.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index f7052e4834a..ae804ad409e 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -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. /// |
