Replace spinlock with condition_variable