I agree, I could add a critical section inside the if (atomic ... ?