Questions
Practice prompts and answer frameworks
Use these as preparation prompts. The goal is to explain your reasoning, trade-offs and failure cases clearly.
How would you detect and fix false sharing?
Two threads update independent counters but performance collapses when they run together. Explain false sharing and how you would prove it.
Answer framework
- Explain cache lines and coherence traffic between cores.
- Describe measurement: benchmark, CPU affinity, perf counters and before/after comparison.
- Fix with padding/alignment, per-thread aggregation or redesigning shared state.
- Warn that padding should be measured and not applied blindly.
Why can heap allocation dominate latency?
A request path allocates many small objects. Explain the costs and redesign the path for predictable latency.
Answer framework
- Mention allocator metadata, locks, fragmentation, cache misses and tail latency.
- Use object reuse, arenas, pools, reserve, contiguous storage and ownership clarity.
- Explain trade-offs: memory footprint, lifetime boundaries and debugging complexity.
- Validate with allocation tracing and latency histograms.
When is relaxed atomic ordering enough?
You need an atomic counter for statistics. Is memory_order_relaxed correct? Explain the condition under which it is safe.
Answer framework
- Separate atomicity from ordering.
- Relaxed ordering can be fine for independent counters where no synchronization or publication depends on the value.
- Do not use relaxed ordering to publish data or coordinate ownership.
- Explain how acquire/release or stronger ordering would be used for handoff.