Skip to content

Commit e10d1c3

Browse files
Rollup merge of rust-lang#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`.
2 parents 344792f + 688db1d commit e10d1c3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/libstd/thread/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,11 @@ impl<T> JoinInner<T> {
12761276
#[stable(feature = "rust1", since = "1.0.0")]
12771277
pub struct JoinHandle<T>(JoinInner<T>);
12781278

1279+
#[stable(feature = "joinhandle_impl_send_sync", since = "1.29.0")]
1280+
unsafe impl<T> Send for JoinHandle<T> {}
1281+
#[stable(feature = "joinhandle_impl_send_sync", since = "1.29.0")]
1282+
unsafe impl<T> Sync for JoinHandle<T> {}
1283+
12791284
impl<T> JoinHandle<T> {
12801285
/// Extracts a handle to the underlying thread.
12811286
///

0 commit comments

Comments
 (0)