In Wikipedia: CircularBuffer section "Difficulties->Always keep one slot open", the author does not mention any requirement of synchronization between threads:
Always keep one slot open
This design always keeps one slot unallocated. A full buffer has at most (size-1) slots. If both pointers refer to the same slot, the buffer is empty. If the end (write) pointer refers to the slot preceding the one referred to by the start (read) pointer, the buffer is full.
The advantage is:
- The solution is simple and robust.
The disadvantages are:
- One slot is lost, so it is a bad compromise when the buffer size is small >or the slot is big or is implemented in hardware.
- The full test requires a modulo operationBlockquote
Why is there no such requirement? The order of execution should be:
Insert new data
Increment the write index
However, what if the compiler reverses the order as an optimization?