标签:style blog http color os io java strong ar
In this article I‘ll discuss the most fundamental technique in concurrent programming known as memory barriers, or fences, that make the memory state within a processor visible to other processors.private volatile long sequence = RingBuffer.INITIAL_CURSOR_VALUE; // from inside the run() method T event = null; long nextSequence = sequence.get() + 1L; while (running) { try { final long availableSequence = barrier.waitFor(nextSequence); while (nextSequence <= availableSequence) { event = ringBuffer.get(nextSequence); boolean endOfBatch = nextSequence == availableSequence; eventHandler.onEvent(event, nextSequence, endOfBatch); nextSequence++; } sequence.set(nextSequence - 1L); // store barrier inserted here !!! } catch (final Exception ex) { exceptionHandler.handle(ex, nextSequence, event); sequence.set(nextSequence); // store barrier inserted here !!! nextSequence++; } }Load Barrier
Memory Barriers/Fences(内存关卡/栅栏 —原文)
标签:style blog http color os io java strong ar
原文地址:http://blog.csdn.net/aigoogle/article/details/39003161