Re: Single writer counter: how expensive is a volatile read?

2016-10-30 Thread Vitaly Davidovich
On Sunday, October 30, 2016, Aleksey Shipilev wrote: > On 10/29/2016 10:31 PM, Vitaly Davidovich wrote: > > There's one thing I still can't get someone at Oracle to clarify, which > > is whether getOpaque ensures atomicity of the read. I believe it would, > > but I

Re: Single writer counter: how expensive is a volatile read?

2016-10-30 Thread Aleksey Shipilev
On 10/30/2016 05:55 AM, Peter Veentjer wrote: > Let me clarify. > The discussion is around removing the volatile read in the inc method. Ah, sorry I misinterpreted the question. It usually goes the other way: the reads vastly outnumber the writes. Well, since the writer is single-threaded, there

Re: Single writer counter: how expensive is a volatile read?

2016-10-29 Thread Aleksey Shipilev
On 10/29/2016 10:13 AM, Peter Veentjer wrote: > So you get something like this: > > public class Counter { > > private final AtomicLong c = new AtomicLong(); > > public void inc(){ > long newValue = c.get()+1; > c.lazySet(newValue); > } > > public long get(){ >