[concurrency-interest] Synchronization of data read by multiple
jmanson at cs.purdue.edu
Tue Oct 25 12:32:05 EDT 2005
Ryan LeCompte wrote:
> I'm a bit unclear with your first answer regarding a non-primitive field.
> What exactly do you mean by "invariant" here? I was thinking of a
> non-primitive field, such as (String foo;) that could be read/modified by
> multiple threads. If the program required that whenever the variable "foo"
> is used in method1, method2, or method3 that it's most recently written
> value is always returned, then method1/method2/method3 would have to be
> synchronized (on the same lock of course) OR the 'foo' variable would have
> to be declared volatile.
I think I may have misinterpreted your question. This is correct.
Having said that, the recent discussion on volatile should be a good
indication that you shouldn't use it unless you are absolutely sure that
it will do what you expect it to do.
More information about the Concurrency-interest