change cmp_xchg to work better