Re: JavaMemoryModel: What do I do with volatiles?

From: Jeremy Manson (
Date: Fri Nov 17 2000 - 22:10:12 EST

> I'm busy fixing volatiles in HotSpot.
> Some months ago I got a "here's what to do with volatiles" list from
> Doug Lea.
> Then about a month ago there was this flurry of emails about volatiles,
> with
> no obvious conclusion (at least not obvious to me). So what do I do
> with them
> now? Is there a conservatively safe thing to do, that I can weaken
> later if
> the JMM decides it's OK?

It depends on the platform. A stronger memory model on an architecture
means that you need to do less.

I think the consensus was that, informally, you have to ensure that when a
thread reads a volatile, it will see everything that was visible to every
thread that has written to that volatile at the last time those threads
wrote to that volatile. Basically, it acts like an acquire.

When a thread t1 writes to a volatile, you will have to do something to
ensure that when a thread t2 reads that volatile, t1 will be able to see
whatever is currently visible to t1. It acts like a release...

JavaMemoryModel mailing list -

This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:28 EDT