Medium
Two atomic counters on the same cache line
Thread 1 increments c.a 100M times; Thread 2 concurrently increments c.b 100M times. a and b are ~8 bytes apart, well within a typical 64-byte cache line. What is the most accurate prediction?
main.cpp
struct Counters {
std::atomic<long> a{0};
std::atomic<long> b{0};
};
Counters c;
// Thread 1: for (...) c.a.fetch_add(1, std::memory_order_relaxed);
// Thread 2: for (...) c.b.fetch_add(1, std::memory_order_relaxed);2 of 51 in Concurrency