From my knowledge, in C the volatile
keyword should be used where concurrent unsynchronized operations are performed on a variable from more than one source (process). If the variable is declared volatile
, then all processes will always directly access the variable from its memory location, as opposed to copying the variable in the microprocessor's cache and accessing it from there.
Note that this will significantly decrease performance for that particular variable. The access time for in-memory variables is in the order of milliseconds, while for 1'st level or 2'nd level cache variables it is somewhere around tenths of nanoseconds, so use them only when all other options have been considered.