Hi
Is it possible that a compiler optimize the second if statement in the following code, (x is an integer with class scope )
void MyClass:foo()
{
if(x)
{
call a function that does the following:
grab a lock; //this important
if(x) //optimize?
{
do something
}
}
}
There are no statements between the first if and the second if statement that would change x.
X is set in another function (both functions are member functions of the same class) and by another thread.
void MyClass::set(int y)
{
x=y;
}
Does the standard say anything in this case? A pointer would highly be appreciated.
Thanks in advance.