Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loop_executor should block on it's work_queue instead of polling #117

Closed
Oberon00 opened this issue Feb 27, 2017 · 3 comments
Closed

loop_executor should block on it's work_queue instead of polling #117

Oberon00 opened this issue Feb 27, 2017 · 3 comments

Comments

@Oberon00
Copy link
Contributor

loop_executor::loop is currently:

    void loop()
    {
      while (!closed())
      {
        schedule_one_or_yield();
      }
      while (try_executing_one())
      {
      }
    }

The first loop repeatedly calls schedule_one_or_yield() which is simply

    void schedule_one_or_yield()
    {
        if ( ! try_executing_one())
        {
          this_thread::yield();
        }
    }

The current implementation uses unnecessary CPU cycles (esp. if all other threads are idle) by busy waiting. As concurrent::sync_queue<work> work_queue already supports a blocking wait_pull_front , it would be better to use a (private?) wait_executing_one that behaves just like try_executing_one but calls work_queue.wait_pull_front instead of try_pull_front.

IMHO, the current implementation is an outright performance bug.

@Oberon00 Oberon00 changed the title loop_executor should block on it's queue instead of polling loop_executor should block on it's work_queue instead of polling Feb 27, 2017
@viboes
Copy link
Collaborator

viboes commented Feb 27, 2017 via email

@viboes
Copy link
Collaborator

viboes commented Feb 27, 2017

Sorry. I didn't saw this was already a github issue.
What about adding a pull request PR?

@Oberon00
Copy link
Contributor Author

Ok, will do (but not before tomorrow).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants