[concurrency-interest] Volatile happens before question

Boehm, Hans hans.boehm at hp.com
Wed Jan 18 13:33:12 EST 2012

I think that almost expresses the right intuition, though it's not very close to real hardware.  In addition to your constraints, a volatile write also has to ensure that it itself becomes visible before a subsequent volatile read by the same thread.

My understanding is that for most real hardware, at least X86 hardware, the cache coherency protocol essentially ensures that once a write is visible to any cache, it is visible to all.  No cache flushes are required for volatile accesses.  Memory fences are typically required primarily to flush (or order writes from) store buffers holding data that hasn't yet made it to the cache.  (On X86, the fence is needed ONLY to order a volatile store and a later volatile load, i.e. the case you missed below.)


> -----Original Message-----
> From: concurrency-interest-bounces at cs.oswego.edu [mailto:concurrency-
> interest-bounces at cs.oswego.edu] On Behalf Of Raph Frank
> Sent: Wednesday, January 18, 2012 2:42 AM
> To: concurrency-interest at cs.oswego.edu
> Subject: Re: [concurrency-interest] Volatile happens before question
> Thanks all, for the info.
> So, for a cache, if there is a write to a volatile variable, the only
> requirement is that you flush the volatile to main memory last.
> So, if the core writes
> A) writes before volatile write
> B) write to volatile
> C) writes after volatile write
> Then the cache can be flushed in the order A and then C and then B?
> So, a core could wait before writing a volatile to main memory, until
> a second write to that cache slot forces a flush (and writing a second
> value to the volatile itself doesn't force a flush)?
> Similarly for a read, reading from a volatile doesn't actually require
> invaliding the read cache.  However, if the volatile is not in the
> cache, then the read cache must be flushed before reading the volatile
> from main memory?
> On Tue, Jan 17, 2012 at 11:45 PM, Vitaly Davidovich <vitalyd at gmail.com>
> wrote:
> > That's true, you're right - I didn't think of that as it does seem
> silly but
> > is allowed.
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest

More information about the Concurrency-interest mailing list