Master the fundamental concepts of memory hierarchy through this focused micro-challenge.
CPUs move data in cache lines (typically 64 bytes). Two independent variables sharing a line sit on the same coherence unit. When one core writes byte 0 and another writes byte 63, both cores invalidate each other's copy even though logical data differs. That is false sharing.
cLoading…
Pad structures to one hot field per line:
cLoading…
Run two threads updating adjacent ints vs padded ints and compare perf c2c or cycle counts.
For this exercise, you will demonstrate slowdown from unaligned hot fields. This task asks you to fix layout with padding and measure the speedup, a routine optimization in Java @Contended, Linux per-CPU counters, and game engine job structs.
Keep the relevant datasheet, ISA manual, or architecture textbook chapter open while you implement. When your output disagrees with the reference trace on the same program, the bug is usually a mis-decoded opcode, a stale register read, or a flag bit left unchanged after arithmetic.
For this exercise, you will use those habits while implementing the requirement in the starter code. Microarchitectural product names change across CPU generations, but the control ideas (fetch, bypass, cache lines, vector lanes) stay stable enough to debug from first principles.
Demonstrate false sharing and cache coherency overhead.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github