Agree with both. Brain fart on my part. Can’t count on counter++ and counter-- being atomic. Simply surrounding them with noInterrupts() / interrupts() pair would fix that.
When I pointed out the flaw in the original code, I explained the problem in detail so the OP could understand. Like I said, my brain fart missing the follow-on issue.
Don’t know why @CB chose to be a jerk and recommend guessing games (“go search for my posts on the internet”) instead of providing a concise explanation.