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

Re: Question about volatile modifier



>
>
>that threads running on different processors immediately see changes to
>volatile variables. Apparently, if thread A running on processor 1 changes
>  
>
Ah!  SMP boxes, good point.    It's easy to forget these details.    SMP 
hardware is
designed with larg'ish per CPU memory caches that allow for threads 
executing java
can have private copies of these shared variables.

Modifications to volitile variables, causes the VM to issue the machine 
instructions to
force all CPU's accessing this memory addresses to re-read the new value.  

Re-remembering a bit more, synchronize / notify does this forced flush 
too.  So the
volitile is only needed for a variable declaration that will be 
intentionally accessed
from multiple threads without the benefit of synchronize / notify, even 
if it's intrinsicly
atomic [int, char ,,,  all object references].

Great comments.

curt

>  
>