2 ms·
Should not be used in linux kernel code, that is. The way I learned volatile was that it's used to tell the compiler not to optimize away a variable that appea
by cratermoon 3y ago
Should not be used in linux kernel code, that is.
The way I learned volatile was that it's used to tell the compiler not to optimize away a variable that appears to not change. If, for example, there's a variable that can be set via an interrupt, outside the local flow of execution. A compiler might cache the value on first read, volatile ensures the variable is read freshly from memory every time.
That does not ensure against unwanted concurrent access, so it's not it a synchronization mechanism.