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 ?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…