[concurrency-interest] atomicity and volatile

Bob Lee crazybob at crazybob.org
Wed Mar 5 19:18:49 EST 2008

On Wed, Mar 5, 2008 at 4:09 PM, Dhanji R. Prasanna <dhanji at gmail.com> wrote:

> Am I correct in assuming that multiple threads could clobber each others
> increments since count++ is not an atomic operation relative to all threads
> calling increment?

You care correct--volatile here is not atomic. If you want the operation to
be atomic, you could use AtomicInteger.incrementAndGet().

-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20080305/b328c089/attachment.html 

More information about the Concurrency-interest mailing list