concurrencyoop
Protect the invariant, not just the counter
Anonymous
If a counter and a related limit must change together, making only the counter atomic can still leave inconsistent state. Put the whole check-and-update under one lock, or use a primitive designed for that combined operation.
0