Beginner question: Why MultiProducerSequencer.next uses compareAndSet instead of addAndGet.

174 views
Skip to first unread message

Andrii Merkushev

unread,
Oct 1, 2019, 9:21:22 PM10/1/19
to Disruptor
Good day, This is my first experiment with the Disruptor.

I have a question why implementation of MultiProducerSequencer.next uses Sequence.compareAndSet to advance cursor instead of Sequence.addAndGet?
Theoretically, fetch_and_add must be faster than compare_and_swap because because it's a single operation and no retries are required. Is compare_and_swap is crucial there?

Thank you,
Andrii

Tom Lee

unread,
Oct 1, 2019, 11:42:03 PM10/1/19
to lmax-di...@googlegroups.com

Entirely possible I'm misunderstanding your suggestion, but pretty sure the CAS is necessary because the whole while loop needs to be retried if another thread progresses the cursor while we're in the middle of checking ring buffer invariants etc.


--
You received this message because you are subscribed to the Google Groups "Disruptor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmax-disrupto...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/lmax-disruptor/55c29d49-f65f-40c2-87fe-73b626fc0124%40googlegroups.com.


--
Tom Lee http://tomlee.co / @tglee

Reply all
Reply to author
Forward
0 new messages