File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed
Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -115,7 +115,15 @@ impl<T> RingBuffer<T> {
115115 // an initialized slot when reading, or to a slot that may be written
116116 // when writing. This helper performs unchecked indexing into the
117117 // backing slice using the internal mask.
118- unsafe { ( & mut ( * self . ptr ) ) . get_unchecked_mut ( idx & self . mask ) }
118+ //
119+ // We use raw pointer arithmetic here to avoid creating a `&mut` reference
120+ // to the entire backing array, which would cause aliasing issues in Miri
121+ // when both producer and consumer threads call this method concurrently.
122+ // Instead, we create a reference only to the specific element we need.
123+ unsafe {
124+ let base = self . ptr as * mut MaybeUninit < T > ;
125+ & mut * base. add ( idx & self . mask )
126+ }
119127 }
120128}
121129
You can’t perform that action at this time.
0 commit comments