Master the fundamental concepts of pipelining & out-of-order execution through this focused micro-challenge.
CPUs and compilers reorder memory operations for speed. Memory barriers (fences) restrict reordering so other cores observe writes in intended order. Lock implementations depend on acquire/release semantics.
cLoading…
MFENCE, SFENCE, LFENCE; locked ops imply strong orderingDMB, DSB, ISBmemory_order_seq_cst maps to fences on weak ISAsFor this exercise, you will demonstrate a litmus test where missing barriers lets a second thread observe ready==1 but stale data. This task asks you to fix ordering with atomics, matching what the Linux kernel documents for spinlock release.
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 memory barriers and ordering.
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