Rearrange atomic checks to remove race