Can Modern x86 Hardware Not Store a Single Byte to Memory?
Stroustrup's statement in his book refers to the potential behavior of hypothetical hardware without a well-defined memory model. He suggests that such hardware might implement byte stores with non-atomic updates, potentially affecting neighboring bytes.
Actual Modern Hardware Behavior
However, modern hardware, including x86, does not behave in the way Stroustrup describes:
Historical Context
Stroustrup's statement may have been based on the behavior of early Alpha AXP processors, which initially did not support byte load/store instructions. However, later versions of Alpha and all modern CPUs support safe and efficient byte stores.
Hardware Implementation
Modern CPUs typically use caches that store segments of memory. In a cached system:
Exceptions
While modern CPUs provide atomic byte stores, there may be exceptions in certain situations:
Conclusion
In practice, modern hardware supports atomic byte stores, making Stroustrup's description of potential hardware behavior less relevant to actual systems. The memory model guarantees provided by C compilers rely on the reliable behavior of modern hardware to ensure thread safety.
The above is the detailed content of Can Modern x86 CPUs Really Not Atomically Store a Single Byte to Memory?. For more information, please follow other related articles on the PHP Chinese website!