Naive implementation of cas()