<batteries/cpu\_align.hpp>: Prevent false sharing by isolating a type in its own cache line(s).
<batteries/cpu_align.hpp>: Prevent false sharing by isolating a type in its own cache line(s).🔗
Features🔗
- Class template batt::CpuCacheLineIsolated for guaranteed cache-line isolation of an object.
Details🔗
Sometimes when objects modified by different threads are packed too
closely in memory, performance can degrade significantly due to a
"ping-pong" effect where each CPU/core that modifies an object in the
same cache line (the minimum-sized block of memory fetched from main
memory into cache) must wait to read changes made to the other objects
in that cache line. This problem can be solved by padding the memory
into which the objects are placed to ensure each resides within its
own cache line. batt::CpuCacheLineIsolated<T>
makes this very
simple and easy to do.