Skip to content

Commit e572c5a

Browse files
committed
Simplify Send/Sync of std::thread::Packet.
1 parent 4cb7370 commit e572c5a

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

library/std/src/thread/mod.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1270,18 +1270,16 @@ pub type Result<T> = crate::result::Result<T, Box<dyn Any + Send + 'static>>;
12701270
// (the caller will never read this packet until the thread has exited).
12711271
//
12721272
// An Arc to the packet is stored into a `JoinInner` which in turns is placed
1273-
// in `JoinHandle`. Due to the usage of `UnsafeCell` we need to manually worry
1274-
// about impls like Send and Sync. The type `T` should already always be Send
1275-
// (otherwise the thread could not have been created) and this type is
1276-
// inherently Sync because no methods take &self. Regardless, however, we add
1277-
// inheriting impls for Send/Sync to this type to ensure it's Send/Sync and
1278-
// that future modifications will still appropriately classify it.
1273+
// in `JoinHandle`.
12791274
struct Packet<'scope, T> {
12801275
scope: Option<&'scope scoped::ScopeData>,
12811276
result: UnsafeCell<Option<Result<T>>>,
12821277
}
12831278

1284-
unsafe impl<'scope, T: Send> Send for Packet<'scope, T> {}
1279+
// Due to the usage of `UnsafeCell` we need to manually implement Sync.
1280+
// The type `T` should already always be Send (otherwise the thread could not
1281+
// have been created) and the Packet is Sync because all access to the
1282+
// `UnsafeCell` synchronized (by the `join()` boundary), and `ScopeData` is Sync.
12851283
unsafe impl<'scope, T: Sync> Sync for Packet<'scope, T> {}
12861284

12871285
impl<'scope, T> Drop for Packet<'scope, T> {

0 commit comments

Comments
 (0)