allthingssecurity commented on code in PR #30861:
URL: https://github.com/apache/camel/pull/30861#discussion_r4707346902


##########
components/camel-disruptor/src/main/java/org/apache/camel/component/disruptor/DisruptorReference.java:
##########
@@ -781,4 +782,54 @@ public void clear() {
             delayedCommands.clear();
         }
     }
+
+    /**
+     * The count of {@link #beginPublish()}, without a write shared by all the 
producers on each publish: a thread
+     * counts in a cell chosen by its id (the same cell for its increment and 
its decrement), alone on its cache line.
+     * <p>
+     * A reconfiguration cannot stop waiting while a producer that read the 
old reference publishes: the producer
+     * increments (a volatile getAndAdd) before its volatile read of the 
reference, and the reconfiguration clears the
+     * reference (a volatile write) before its volatile reads of the cells, so 
the cell read sees the increment of a
+     * producer that read the old reference. As a thread decrements the cell 
it incremented, after it, a cell is never
+     * below 0, and reads 0 only when each increment it holds has its 
decrement: the cells being read one after the
+     * other can only make the wait longer. A LongAdder does not keep that: it 
can move a thread to another cell between
+     * its increment and its decrement, so a sum can see the decrement of a 
producer without its increment, which hides
+     * another producer in flight.
+     */
+    private static final class PublishesInFlight {
+        // 16 longs: 128 bytes, the larger cache line (such as on Apple 
silicon), so that no two cells share one
+        private static final int PAD = 16;
+
+        private final AtomicLongArray cells;
+        private final int mask;
+
+        PublishesInFlight() {
+            // a power of 2, at least the number of processors, at most 64

Review Comment:
   Done in ad3c062af502: the comment now says the count is at least the number 
of processors only up to 64 cells, and that above that some threads share a 
cell, which stays correct since each thread adds and removes its own count in 
the cell it uses.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to