// The non-atomic summation doesn't always yield the correct result // (though mostly it is correct too). // I think we're just not doing it right. The synchronization provided // by the queue apparently doesn't protect us as a client when we // fidget with non-synchronized primitive fields... who would have // known :] sclass CompactQTest { long acc; new AtomicLong atomicAccumulator; int n = 100000; new CompactQ q; int qSizeAtEnd; long time; Scorer scorer; begin. long expectedResult = longMul(n, n+1)/2; printVars(+n, +expectedResult); S name = "Queue " + n; time name { for (r : inclusiveCountIterator(1, n, i -> r { acc += i; add(atomicAccumulator, i); })) q.add(r); qSizeAtEnd = q.size(); q.waitUntilDone(); assertEqualsVerbose(scorer, "Non-Atomic", expectedResult, acc); assertEqualsVerbose(scorer, "Atomic", expectedResult, atomicAccumulator!); } time = lastTiming(); print(n2(acc) + " // " + n2(qSizeAtEnd)); }