Hi everyone
My first post on JavaRanch ;)
I've been looking for an answer to my question for quite some time. No luck though...
Let's say one
thread waits for changes of variable int "state".
First it enters synchronized block synchronized(guard) modifies "state" and releases lock of the guard object via guard.wait().
Now second thread modifies variable "state" also in synchronized block notifies first thread and leaves the block.
First thread resumes from wait() and checks the value of "state"
My question is. Does the "state" variable is being flushed to original location in memory from CPU registers
when wait() is called? In other words does thread 2 sees changes made by thread 1 before calling wait()?
I know that variables are "flushed" when synchronized block is reached and leaved but I'm not sure
about that wait() call. In theory wait() releases lock so all variables that has been modified and are in registers
should be flushed...
To clarify I'm talking about non-volatile variables.
Hope you can help me
Cheers