Day60 - Atomics / Memory Ordering / Futex Foundation¶
Date¶
2026-05-26
Goals¶
Learn synchronization foundations in Linux userspace.
Topics:
- race condition
- C11 atomics
- compare-and-swap
- memory ordering
- futex concept
- synchronization primitive selection
Completed¶
Lab1 — Race Condition¶
Implemented shared counter without synchronization.
Result:
Expected:
Observed:
Finding:
Operation is not atomic.
Lab2 — Atomic Counter¶
Replaced shared integer with:
Result:
Finding:
Atomic operation guarantees correctness.
Lab3 — CAS Spin Lock¶
Implemented custom spin lock using:
Protected:
Result:
Observation:
CPU contention became noticeable.
Learned:
- busy wait
- cache contention
- lock overhead
Lab4 — Memory Ordering¶
Implemented producer / consumer synchronization.
Version 1:
Version 2:
Result:
Learned:
Visibility and ordering are independent from atomicity.
Key Takeaways¶
Synchronization hierarchy:
Next¶
Day61:
- pthread mutex internals
- futex wait/wake
- condition variable internals