OK, I'd admit that my personal preference is for the strong
But in the two most common uses of volatiles, it won't make a
In one case, as you would see in ConcurrentHashMap, all threads that
to write to the volatile will be serialized by holding a regular lock
while the volatile
is being updated. In this case, each thread that grabs the lock will be
with all previous threads that updated the volatile, so the weak vs.
In the other common case, a volatile field is used to store a reference
to an object. Anyone
who reads that volatile field and gets a particular reference only
cares about being
synchronized with respect to the thread that wrote the reference it
saw, not with regards to
other threads who wrote to that volatile.
This really is a corner case, and effects things such as whether you
can use volatiles
to force things like memory barriers and to implement subtle
concurrency idioms such
as the optimistic read idiom. Using the strong interpretation will
make a difference to 30
very clever people who will be able to use it to implement some subtle
efficient concurrent algorithms.
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:01:00 EDT