An atomic operation happens all at once from every other thread's point of view. std::atomic<T> offers them for integers, pointers and bool:
load() and store(v) read and write.
fetch_add(n) and fetch_sub(n) change the value and return the old one, in one step. exchange(v) stores a new value and returns the old.
compare_exchange_weak(expected, desired) stores desired only if the value still equals expected, and returns whether it did; if not, it copies the current value into expected. In a loop it builds any update: a running maximum, a capped total, a move from one state to the next.
compare_exchange_weak may fail now and then even when the values match, so it always goes in a loop; compare_exchange_strong never fails that way.
The tests here call your code from one thread, so they check the logic of each update, and a rule on your code checks that the update is a single atomic step. The habit to practice: every decision uses the value the atomic operation returned, never a separate earlier read.
A compare_exchange loop that only ever raises the value.