Skip to content

Commit

Permalink
Clean up atomic increments
Browse files Browse the repository at this point in the history
Signed-off-by: acarbonetto <[email protected]>
  • Loading branch information
acarbonetto committed Oct 3, 2023
1 parent b6d9430 commit a783462
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,12 @@ private static void testConcurrentClientSetGet(
concurrentTaskIndex++) {
tasks.add(
() -> {
int iterationIncrement = iterationCounter.get();
int iterationIncrement = iterationCounter.getAndIncrement();
while (iterationIncrement < iterations) {
int clientIndex = iterationIncrement % clients.size();
// System.out.printf(
// "> iteration = %d/%d, client# = %d/%d%n",
// iterationIncrement + 1, iterations, clientIndex + 1, clientCount);
System.out.printf(
"> iteration = %d/%d, client# = %d/%d%n",
iterationIncrement + 1, iterations, clientIndex + 1, clientCount);

Pair<ChosenAction, Long> result =
async ?
Expand All @@ -278,7 +278,7 @@ private static void testConcurrentClientSetGet(

// save tik-tok to intermediate actionResults
intermediateActionResults.add(iterationIncrement, result);
iterationIncrement = iterationCounter.incrementAndGet();
iterationIncrement = iterationCounter.getAndIncrement();
}
});
}
Expand All @@ -297,7 +297,7 @@ private static void testConcurrentClientSetGet(

System.out.println("WAIT 10 SECONDS");
try {
Thread.sleep(1000L); // TODO update to 10 seconds
Thread.sleep(10000L); // TODO update to 10 seconds
} catch (InterruptedException interruptedException) {
throw new RuntimeException("INTERRUPTED");
}
Expand All @@ -309,7 +309,7 @@ private static void testConcurrentClientSetGet(
concurrentTaskIndex++) {
tasks.add(
() -> {
int iterationIncrement = fetchAsyncFuturesCounter.get();
int iterationIncrement = fetchAsyncFuturesCounter.getAndIncrement();
while (iterationIncrement < iterations) {
Pair<ChosenAction, Future<?>> futurePair = futures.get(iterationIncrement);
int clientIndex = iterationIncrement % clients.size();
Expand All @@ -326,7 +326,7 @@ private static void testConcurrentClientSetGet(
Long intermediateResult = intermediateActionResults.get(iterationIncrement).getRight();
actionResults.get(futurePair.getLeft()).add(
result.getRight() + intermediateResult);
iterationIncrement = fetchAsyncFuturesCounter.incrementAndGet();
iterationIncrement = fetchAsyncFuturesCounter.getAndIncrement();
}
}
);
Expand Down

0 comments on commit a783462

Please sign in to comment.