I'm reading an ebook. they're using volatile keywords for a variable.
This is my example code:
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 fasterCode:volatile boolean check; int a ; //other function public void functionA(){ check = true; while(a>0){ a--;} }
It means in real, this code might run like:
Does this statement true ? I feel very strange of this because I have never heard this before.Code:while(a>0){ a--;} check = true;
thanks![]()



1Likes
LinkBack URL
About LinkBacks



