Let's explore what's going wrong here. Our ring is laid out in memory as a contiguous block and we have a few control variables hung off the side. Here's a diagram of the system before any reads or writes happen:
size: 0 capacity: 5 rdr | |0: None |1: None |2: None |3: None |4: None | | wrt
Here's a diagram of the system just after the writer has written its first value:
size: 0 capacity: 5 rdr | |0: Some(0) |1: None |2: None |3: None |4: None | | wrt
To do this, the writer has performed a load of both size and capacity, performed a comparison between then, written to its offset inside the block, and incremented size. None of these operations are guaranteed to be ordered as they are in the program, either due to speculative ...