I wrote about a Lock Free Concurrent Circular Buffer about a year ago. This has now been updated to support multiple independent readers, so many consumers can get updates to this circular buffer.
It is still lock free, so the readers won't block. If you try to take() on a buffer with no updates a null is returned, and if you drain() a buffer with no updates you get an empty list.
The code is now on GitHub, so I recommend you give it a spin if you want a (simple) circular buffer. It does detect buffer wraparounds, but will in this case reset the reader to the end of the buffer, losing any intermediate updates. Tune your buffer size accordingly.
Take a look at the unit tests to get an idea on how to use this buffer.
0 kommentarer:
Legg inn en kommentar