Skip to content

Commit

Permalink
impr: add T: Send for AtomicLazyCell Sync impl
Browse files Browse the repository at this point in the history
Add a `T: Send` to the existing `T: Sync` restriction on the `AtomicLazyCell`
`Sync` impl.
This is necessary because filling an `AtomicLazyCell` only requires a reference
to the cell (i.e. `&AtomicLazyCell`), which means that an empty
`&AtomicLazyCell<T>` can be passed to a child thread (provided that
`AtomicLazyCell<T>: Sync` is satisfied), and filled on the child thread.
The filled value would then be on the stack of, and destroyed by, the
parent thread.

Kudos to dbaupp on Reddit for this recommendation.

Closes #67.
BREAKING CHANGE: the `AtomicLazyCell` `Sync` impl now has a `<T: Sync + Send>`
    constraint instead of a `<T: Sync>` constraint.

    To migrate your code, remove any `AtomicLazyCell<T>` instances where
    `<T: Sync + !Send>`, as this usecase is no longer supported.
  • Loading branch information
indiv0 committed Nov 25, 2017
1 parent bb51247 commit 668bb2f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl<T: Copy> AtomicLazyCell<T> {
}
}

unsafe impl<T: Sync> Sync for AtomicLazyCell<T> {}
unsafe impl<T: Sync + Send> Sync for AtomicLazyCell<T> {}

unsafe impl<T: Send> Send for AtomicLazyCell<T> {}

Expand Down

0 comments on commit 668bb2f

Please sign in to comment.