When is an atomic not enough?

medium~15 min#atomics#c++#concurrency#mutex

You have two variables that must always be updated together — a balance and a transaction count, say. A colleague proposes making both std::atomic and dropping the mutex, arguing it is faster and cannot deadlock.

What do you tell them?

Solution — locked

Sign in to unlock this one

The solution opens once you explain the idea in your own words and it passes the grader — which needs an account to record. Signing in is free.

Log in