Use pointers instead of &self
in Latch::set
#1011
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Latch::set
can invalidate its own&self
, because it releases theowning thread to continue execution, which may then invalidate the latch
by deallocation, reuse, etc. We've known about this problem when it
comes to accessing latch fields too late, but the possibly dangling
reference was still a problem, like rust-lang/rust#55005.
The result of that was rust-lang/rust#98017, omitting the LLVM attribute
dereferenceable
on references to!Freeze
types -- those containingUnsafeCell
. However, miri's Stacked Borrows implementation is finer-grained than that, only relaxing for the cell itself in the
!Freeze
type. For rayon, that solves the dangling reference in atomic calls, but
remains a problem for other fields of a
Latch
.This easiest fix for rayon is to use a raw pointer instead of
&self
.We still end up with some temporary references for stuff like atomics,
but those should be fine with the rules above.