I'm reading an ebook. they're using volatile keywords for a variable.
This is my example code:
Code:
volatile boolean check;
int a ;
//other function
public void functionA(){
check = true;
while(a>0){ a--;}
}
They explain check variable is volatile because: the compiler might decide to reorder the statements in function A if it recognizes that there are no dependencies. It is allowed to do this if it thinks it will make the code execute faster
It means in real, this code might run like:
Code:
while(a>0){ a--;}
check = true;
Does this statement true ? I feel very strange of this because I have never heard this before.
thanks