Skip to content

[Question] Is it intentional that static_thread_pool is basically spinlocking when idle? #1475

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

Closed
miwechner opened this issue Feb 14, 2025 · 2 comments

Comments

@miwechner
Copy link

miwechner commented Feb 14, 2025

Hi,

Thanks for your work, I am really enoying working with S&R.

I wanted to use exec::static_thread_pool in a GUI application and noticed that I have very high CPU usage when I create an exec::static_thread_pool without enqueuing anything. I think it comes down to this function which means one stealer thread is always kept alive and attempts to pop the queues, even though nothing has been enqueued.

inline void static_thread_pool_::thread_state::clear_stealing() {
if (pool_->numThiefs_.fetch_sub(1, std::memory_order_relaxed) == 1) {
notify_one_sleeping();
}
}

I guess this is intentional to reduce latency, but when i started i have to say that this behaviour wasn't clear to me. I also could not find any documentation for static_thread_pool or issue here on Github talking about this. So i am asking just in case for me and for anyone else that would attempt the same.

Thanks,

Michael

@maikel
Copy link
Collaborator

maikel commented Feb 14, 2025

Lets say its at least a known issue. It was discussed in issue #1305 and your question is another motivational push to change that.

@maikel
Copy link
Collaborator

maikel commented Feb 15, 2025

Hi Michael,

I made a PR where the pool only wakes up new thiefs if at least one victim is awake. If it is the last thread it will be put to sleep.

Can you try that, whether it fits better?

Thank you for reporting the issue!

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

No branches or pull requests

2 participants