Managing Volatility in the Java World (developerWorks)
[Posted June 19, 2007 by ris]
IBM developerWorks looks
at volatility in Java. "The Java language contains two intrinsic
synchronization mechanisms: synchronized blocks (and methods) and volatile
variables. Both are provided for the purpose of rendering code
thread-safe. Volatile variables are the weaker (but sometimes simpler or
less expensive) of the two -- but also easier to use incorrectly. In this
installment of Java theory and practice, Brian Goetz explores some patterns
for using volatile variables correctly and offers some warnings about the
limits of its applicability."
(Log in to post comments)
Managing Volatility in the Java World (developerWorks)
Posted Jun 19, 2007 18:24 UTC (Tue) by jengelh (subscriber, #33263)
[Link]
Managing Volatility in the Java World (developerWorks)
Posted Jun 19, 2007 20:16 UTC (Tue) by ibukanov (subscriber, #3942)
[Link]
volatile in Java and C# has precise semantics which makes it useful in certain situations especially in connections with synchronized statement like those described in the article.
On the other hand in C locks and semaphores are done through libraries so semantics of synchronization primitives in C in presence of volatile keyword completely platform-dependent. So, as Linus suggested in the above thread, one better code those assumptions directly in assembler rather documenting/asserting properties of volatile under the specific compiler and OS.