uh... compare & swap is most certainly possible to write safely for the sole purpose of either obtaining a lock or failing (and perhaps retrying).
or, are you one of those people that think it is not possible to walk down the sidewalk safely? the CIA radio signals are putting the CPU into backdoor mode, right?