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

coro::thread_pool high cpu usage when tasks < threads #265

Merged
merged 3 commits into from
Jul 5, 2024

Conversation

jbaldwin
Copy link
Owner

The check for m_size > 0 was keeping threads awake in a spin state until all tasks completed. This correctl now uses m_queue.size() behind the lock to correctly only wake up threads on the condition variable when tasks are waiting to be processed.

Closes #262

@jbaldwin jbaldwin self-assigned this May 24, 2024
src/thread_pool.cpp Outdated Show resolved Hide resolved
@jbaldwin jbaldwin force-pushed the issue-262/high-cpu-thread-count branch 3 times, most recently from 1237316 to c9bb47c Compare May 24, 2024 02:37
The check for m_size > 0 was keeping threads awake in a spin state until
all tasks completed. This correctl now uses m_queue.size() behind the
lock to correctly only wake up threads on the condition variable when
tasks are waiting to be processed.

* Fix deadlock with task_container and tls::client with the client's
  destructor scheduling a tls cleanup task, the task_container's lock
was being locked twice when the cleanup task was being destroyed.

Closes #262
@jbaldwin jbaldwin force-pushed the issue-262/high-cpu-thread-count branch from c9bb47c to 567f4a8 Compare June 9, 2024 20:59
It is now deleted inline in make_user_task so any destructors that get
invoked that possibly schedule more coroutines do not cause a deadlock
@jbaldwin jbaldwin merged commit 5697678 into main Jul 5, 2024
41 checks passed
@jbaldwin jbaldwin deleted the issue-262/high-cpu-thread-count branch July 5, 2024 18:29
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

Successfully merging this pull request may close these issues.

High CPU usage, when thread_count is greater than the number of tasks
1 participant