Skip to content

Race condition when setting m_is_paused in urd::command_handler()

The following code in urd::command_handler() causes a race condition if m_is_paused is set by another thread after its value is checked and before setting it to true:

if(!m_is_paused) {
    m_is_paused = true;
}

Similarly with:

if(m_is_paused) {
    m_is_paused = false;
}

The consequences of such a race condition should not be critical, but it is an error nonetheless. The correct way of doing it is using the compare_exchange_*() family of functions to test and set the flag atomically.