Consider a simple (global in my case) variable:
int i;
Somewhere this variable is accessed
pthread_mutex_lock(i_mutex);
if(i == other value) {
do_something();
}
pthread_mutex_unlock(i_mutex);
Another thread updates i
while it holds i_mutex
. Could the compiler cache the value of i
so
I don't get the recent value ? Must i
be volatile ?