No mention of volatile variables or the concept of stale cpu cache reads when a value is written to from another core. I think its a pretty common and fundamental concept that should be in a write up such as this.
If you use the standard blocking synchronization primitives, you cannot have stale reads. If you don't, the right way to introduce them would be with the C11 memory model relationships (synchronizes-with, happens-before), volatile shouldn't be touched with a 10 foot pole except for synchronization with signal handlers.
Every multiprocessor system nowadays has coherent caches for normal memory, meaning that if you have reads that you perceive as stale, it isn't because of the cache, but because the hardware doesn't guarantee sequential consistency.
You can have problems due to relaxed consistency on a system without caches, and the problems on systems with caches aren't due to the caches.
There are situations when you have to worry about lack of coherency for other memory types, but AFAIK these are rarely exposed to userspace.
I agree it would be nice to add. Is that something you need to worry about when using the standard synchronization APIs though? They all handle memory fencing for you, no?
Comments
No mention of volatile variables or the concept of stale cpu cache reads when a value is written to from another core. I think its a pretty common and fundamental concept that should be in a write up such as this.
If you use the standard blocking synchronization primitives, you cannot have stale reads. If you don't, the right way to introduce them would be with the C11 memory model relationships (synchronizes-with, happens-before), volatile shouldn't be touched with a 10 foot pole except for synchronization with signal handlers.
Every multiprocessor system nowadays has coherent caches for normal memory, meaning that if you have reads that you perceive as stale, it isn't because of the cache, but because the hardware doesn't guarantee sequential consistency.
You can have problems due to relaxed consistency on a system without caches, and the problems on systems with caches aren't due to the caches.
There are situations when you have to worry about lack of coherency for other memory types, but AFAIK these are rarely exposed to userspace.
I agree it would be nice to add. Is that something you need to worry about when using the standard synchronization APIs though? They all handle memory fencing for you, no?