Closed Petrakeas closed 8 years ago
I like the PR, I'll review in detail next week.
Ok the minimal fix for this bug is actually line 96.
The rest shouldn't change the semantics; I think I was focused on preserving the ordering of the cursors but neglected the entries.
I like the acquire/release pattern, probably a little easier to reason about, so I'll accept.
It's line 96 and line 52 (for the read-acquire part).
The Memory Barriers used in RingBuffer do not prevent reordering of read and write instructions when accessing _entries and the producer cursor. This could have an effect that the consumer reads a value from _entries before it gets actually updated, thus returning an older value.
This pull request makes sure that the producer writes the new value in
_entries
and then updates the producer cursor (to signal that the data are ready to be used). The consumer first reads the producer cursor to make sure that the data are ready and then reads the actual data stored in_entries
to make sure it reads the latest value.The updated benchmark script adds increasing numbers. Thus, when dequeuing items, we can check their value with the expected one.
Please read the corresponding issue: https://github.com/dave-hillier/disruptor-unity3d/issues/5