LMAX disruptor busy spin vs ConcurrentLinkedQueue

397 Views Asked by At

When studying the LMAX disruptor I noticed that it uses the ring buffer model using the busy spin model with the CAS (compare-and-swap) to avoid locks like those that exist in a blocking queue, but what are the differences and advantages when comparing using ConcurrentLinkedQueue which also has no locks and also uses CAS?

I noticed that both use CAS inside a loop and avoid locks and waits between threads, but I couldn't understand the point where they diverge.

1

There are 1 best solutions below

0
prashant On

Disruptor Provides lock-free and avoids cache misses by using "mechanical sympathy". Compared to blocking queues it provides multicast to consumers, pre-allocate memory and lock-free. All memory visibility and correctness guarantees are implemented using memory barriers and/or compare-and-swap operations. Different wait strategies are available based on kind of processing power One sample is YieldingWaitStrategy. In this thread informs the os that its willing to relinquish its current use of processor to other threads .this strategy is used for low latency and where number of handler threads are less than number of processors and hyperthreading is enabled. Threads do a busy spin to get to the sequence .