Search code examples
chroniclechronicle-queue

What is Chronicle-Queue MT visibility guarantee in a single process?


I mean when I write to java.util.concurrent.LinkedBlockingQueue I have a visibility guarantee happens-before. Single object put to the queue happens-before pull of the same object from the queue. So I can assume in the reading thread, that any other state of variable is not older then the time at which the object was put to the LBQueue.

Do we have the same visibility guarantee in Chronicle-Queue ?

Do we have the same visibility guarantee in any of the usage style ( methodReader/writer vs wire().read().object() ) ?


Solution

  • Indeed you have the same (in fact, slightly stronger) guarantee. Each write to Chronicle Queue (in any style) results in a sequence of volatile write/reads to the memory-mapped file, hence provides memory barriers.

    Additionally, each write is guarded by a write lock, which is implemented as a CAS-driven update to a value stored in a memory-mapped file.