Use an atomic reference instead of volatile.