The use of volatile
in multi-threaded code is generally suspect. volatile
was designed to avoid optimizing out reads and writes to memory, which is useful when such reads and writes occur on special addresses that map to hardware registers. See, for example, how volatile
is useless to prevent data-races, and how it can be (ab)used as a phantom type...
Since the author used proper synchronization (mutexes and condition variables), the use of of volatile
is extremely suspect. Such uses generally stem from a misunderstanding, most notably spread by languages such as Java who reused the same keyword with different semantics.
In C and C++, multi-threaded code should rely on memory barriers, such as those introduced by the mutexes and atomic operations, which guarantee that the values are correctly synchronized across the different CPU cores and caches.