Practice ยท 3 of 3
Split the Cache Lines
CHALLENGE
Difficulty: advanced+25 XP
ISO C11 + hardware reality. Two counters sit in one struct: struct hot { atomic_int a; atomic_int b; }; Given a padded variant struct padded { atomic_int a; char pad[60]; atomic_int b; }; (sizeof(atomic_int)==4 on this target), implement int same_line(const void *p, size_t offset_a, size_t offset_b) โ return 1 when the two byte offsets share the same 64-byte cache line, 0 otherwise. Then the checkpoint question: which member offsets in struct hot are same-line?
Press Submit to check your solution.
Back to lesson: Practice: Atomics and Ordering Drills