[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Question about volatile modifier



One other thing that the keyword volatile does for concurrency is to ensure
that threads running on different processors immediately see changes to
volatile variables. Apparently, if thread A running on processor 1 changes
variable x, thread B running on processor 2 can subsequently read an old
version of x because threads are allowed to keep copies of variables in
private working memory areas. These areas are reconciled with the main,
shared memory only at synchronization points. This is true even for atomic
data types. However, when a volatile variable is updated, main memory is
updated and the change is immediately visible to all threads.

This information is from Peter Hagar's _Effective_Java_ book in the Praxis
50 section.

- Jim