Skip to content

run_loop::state_t::pop() wakes up prematurely #734

Description

@nomevas

The predicate in the second cv.wait_for is incorrect:

m_cv.wait_for(lock, m_queue.top()->get_timepoint() - now, [&]() { return is_disposed() || !m_queue.is_empty() || m_queue.top()->get_timepoint() <= worker_strategy::now(); });

!m_queue.is_empty() is "always" true at this point, because we’re already in a scope where that condition has been checked. As a result, the predicate immediately evaluates to true, making the wait return right away and causing a busy loop. This leads to high CPU usage when using interval operators combined with run loops.

Fix suggestion, change predicate to:

m_cv.wait_for(lock, m_queue.top()->get_timepoint() - now, [&]() { return is_disposed() || m_queue.is_empty() || m_queue.top()->get_timepoint() <= worker_strategy::now(); });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions