Skip to content

Conversation

@jbaldwin
Copy link
Owner

std::deque with std::mutex and std::condition_variable are easy to use but atrocious for performance. Using a relatively drop in replacement moodycamel::BlockingConcurrentQueue to speed up the scheduling of tasks onto a thread pool.

Noted items:

  • a coroutine in a while(cond) { co_await tp->yield(); } loop where the thread_pool only has 1 executor thread causes an infinite loop, I've worked around this by using queue.wait_dequeue_bulk_timed() to guarantee multiple tasks get executed per executor loop, this is not done with multiple executor threads since we want to distribute the work more evently.

Closes #404

@jbaldwin jbaldwin self-assigned this Oct 28, 2025
@jbaldwin jbaldwin force-pushed the issue-404/mpmc-lockless-workstealing-queue branch from 16d4669 to c0cde70 Compare October 28, 2025 12:07
std::deque with std::mutex and std::condition_variable are easy to use
but atrocious for performance. Using a relatively drop in replacement
moodycamel::BlockingConcurrentQueue to speed up the scheduling of tasks
onto a thread pool.

Noted items:
* a coroutine in a while(cond) { co_await tp->yield(); } loop where the
  thread_pool only has 1 executor thread causes an infinite loop, I've worked
  around this by using `queue.wait_dequeue_bulk_timed()` to guarantee
  multiple tasks get executed per executor loop, this is not done with
  multiple executor threads since we want to distribute the work more
  evently.

Closes #404
@jbaldwin jbaldwin force-pushed the issue-404/mpmc-lockless-workstealing-queue branch 2 times, most recently from 40d6375 to b9eb98a Compare October 28, 2025 14:03
cleanup shared mutex test, needed a yield on cleanup
@jbaldwin jbaldwin force-pushed the issue-404/mpmc-lockless-workstealing-queue branch 4 times, most recently from cfc9cf8 to add42f5 Compare October 28, 2025 19:04
@jbaldwin jbaldwin force-pushed the issue-404/mpmc-lockless-workstealing-queue branch from add42f5 to a651ef3 Compare October 28, 2025 22:25
Large benchmark gains on io_scheduler tcp/tls.
@jbaldwin jbaldwin force-pushed the issue-404/mpmc-lockless-workstealing-queue branch from 63a3d33 to 7b403bb Compare October 29, 2025 04:13
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.

Performance in recursive fork/join is very poor

2 participants