Hopefully dumb question ;-) I tried reading the JSL but I must have missed it. When using a synchronized block, ignoring the locking aspect and thinking in terms of synchronizing the threads view of memory as a communication aid between threads, what guarantees do you get ..
e.g.
// this
thread may not have the latest annotherObject here (cached)
synchronized (lockobject)// B:
{
// A: use other (non volatile) member variable here
// (obviously not locked)
if (annotherObject != null)
{
System.out.println ("its null");
}
}
i.e.
when synchronized is called does it sync all threads view of memory, or is it limited to the object being locked in some way i.e. provided another thread doesn't change annotherObject between A: and B: will its value be correct (current always\non cached)at B: or is it still possible to see a stale (cached) value of annotherObject as it itselft isn't locked or was it sync'ed in terms of its value when we entered the synchronized block, like it was volatile at that point i.e. did it drop the threads cached view of the world (if it had one).
Just to be clear I'm quite clear on what's locked and isn't (i.e. you can assume any other thread changing anotherObject must enter a synchronized lockObject block) , I just need a bit clearer view of how thread caching can work and when the thread is guaranteed to have the true latest version of a non locked variable. I hope that makes sense.