[concurrency-interest] Relativity of guarantees provided by volatile

Marko Topolnik mtopolnik at inge-mark.hr
Tue Aug 21 17:46:19 EDT 2012

> Similar to your concern that consecutive volatile writes can be
> compressed into the last write, it also seems true that consecutive
> volatile reads can be compressed into the first read - exactly the
> kind of optimization to be disabled by C's volatile. It's
> inconceivable that any JVM will do such optimization on volatile
> reads, it'll break lots of programs, e.g. busy waits.

Actually there is already a provision in the JMM (in the original paper, at least) that prevents a busy-waiting loop whose condition involves a volatile read to forever read a stale value. There can be only a finite number of such read actions. But, this is a small consolation, really. Most code DOES make a difference between "eternity minus one" and "right now".


More information about the Concurrency-interest mailing list