AdvancedMultiple choice
Per-thread counters · Part 3 of 3
Sixteen worker threads count the messages they handle in std::atomic<uint64_t> counts[16], a contiguous array that starts on a 64-byte cache-line boundary. Each thread increments only its own element.
A monitoring thread reads all sixteen counters once a second, and nothing else depends on their values. What is the weakest memory order for the increments that is still correct?
- A
memory_order_relaxed - B
memory_order_release, paired with acquire loads in the monitor - C
memory_order_seq_cst, the default - DA plain non-atomic
uint64_t, since each counter has a single writer and the monitor only reads it
The worked solution is in Premium
The answer, the full working and the one idea to take away – for this and all 1,322 questions in the bank. Answer it in practice and your working is marked, with a known mistake named when you make one.
Learn the method
More systems and low latency questions
- A ring buffer has capacity 1024 and wraps its index with a bit mask instead of a modulo.Foundation
- Five per cent of a workload is inherently serial.Applied
- A system handles 10⁶ messages a second with an average time in system of 5 μs.Applied
- Thread 1 locks A then B; thread 2 locks B then A.Applied
- Messages arrive at 400,000 a second and take 2 μs each to process on one thread.Advanced
- What synchronisation does a single-producer, single-consumer ring buffer need…Advanced