1

In LMAX-Exchange/Disruptor 3.4.3, RingBuffer put 7 long padding fields (via extends RingBufferPad) before its really fields

abstract class RingBufferPad
{
    protected long p1, p2, p3, p4, p5, p6, p7;
}

and put another 7 long padding fields at the end to avoid false sharing

public final class RingBuffer<E> extends RingBufferFields<E> implements Cursored, EventSequencer<E>, EventSink<E>
{
    public static final long INITIAL_CURSOR_VALUE = Sequence.INITIAL_VALUE;
    protected long p1, p2, p3, p4, p5, p6, p7;

The question is why putting 7 long padding fields, not 6 fields as described in Mechanical Sympathy - False Sharing.

public final static class VolatileLong
{
    public volatile long value = 0L;
    public long p1, p2, p3, p4, p5, p6; // comment out
}
assylias
  • 321,522
  • 82
  • 660
  • 783
Jacky1205
  • 3,273
  • 3
  • 22
  • 44
  • If you look at the comment section of the linked article, many people suggest that having only 6 padding variables is wrong and that p7 is missing. – kapex Jul 24 '18 at 09:40

0 Answers0