How could I know a variable is read from memory not register without using volatile.
static uint64 counter;
void thread(void *arg){
while(counter < (uint64)arg){
acquire(&lock)
counter++;
release(&lock);
}
}
I never doubt with that before, but if there's compiler optimization, won't it produce bad result. I also find the volatile is rare in xv6 kernel code, and I wonder is there some tricks to suppress optimization through compiler's command line to prevent use of volatile.