LWN.net Logo

Managing Volatility in the Java World (developerWorks)

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]

http://lkml.org/lkml/2006/7/6/293
Now maybe Java does not only run kernels, but hey, when was the last time you needed volatile?

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.

Copyright © 2007, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds