← InterviewIntermediate

What Does an Atomic Actually Make Atomic?

You replace a mutex-protected integer with an atomic. What have you gained, and what have you not?

The scenario

A rate limiter uses std::atomic<int> inFlight. The code reads it, compares against a cap of 50, and increments if under. Under load, inFlight regularly reaches 56.

What it tests

  • Whether the candidate knows the atomicity boundary is one operation, not one variable
  • Whether they can identify multi-step invariants that atomics cannot protect
  • Whether they know what compare-and-swap adds and what a CAS loop costs

Answer it out loud first. Recognising a good answer is not the same skill as producing one.