[concurrency-interest] LongAdder with custom behavior?

Doug Lea dl at cs.oswego.edu
Sat Dec 2 08:41:30 EST 2017

On 12/01/2017 02:18 AM, Carl Mastrangelo via Concurrency-interest wrote:

> I would like sumThenReset to tally up all the mutations, and reset
> the counter back to zero without dropping mutations.  This would make
> it so I call sumThenReset later, and pick up any mutations I missed.

It sounds like you are looking for a SNZI (scalable non-zero indicator).
(Google it). We ought to consider supplying one.

> the implementation of sumThenReset does two volatile operations on
> each Cell.value.  First it reads, followed by setting it to zero.
> Why doesn't it use getAndSet on the value?

Yes; thanks. This should usually be faster. Changes are now in jsr166
CVS and should some day propagate.


More information about the Concurrency-interest mailing list