Set m_terminated = true at the beginning of terminate().