On 09/29/2012 09:06 PM, Benjamin Wang (gendwang) wrote:
Hi,
I think you misunderstand my meaning. My solution includes step1 +
step2. Step1 is used to implement thread mutex. Step2 is used to
handle “initialized” visibility. Without step2, the initialization
could be executed several times.
B.R.
Benjamin Wang
Okay, your solution probably work in Java because the visibility feature
of "volatile", that is to say
A |volatile| variable is not allowed to have a local copy of a variable
in thread-local memory that is different from the value currently held
in "main" memory. whenever you access or update the variable in any
thread, all other threads immediately see the same value.
But in C I am not quite sure that volatile will work like what it does
in Java or it could work well with
"synchronized" code in Java.