Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7609693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:14:05+00:00 2026-05-31T01:14:05+00:00

I’m currently in the need of a simple and efficient thread pool implementation. I

  • 0

I’m currently in the need of a simple and efficient thread pool implementation. I have searched here and also on Google and found numerous interesting links, but nothing i’ve found so far seems to be suitable. Most of the implementations i have found on the web are either too complicated or lack some of the key features i need.

Also i don’t want to use code that i do not understand, so i decided to code it myself (sometimes reinventing the wheel helps me push myself forward in terms of knowledge and experience). I of course understand the basic idea behind thread pool, but some implementation details are still somewhat unclear to me. This is probably because the kind of thread pool i need is a bit special. Let me describe it. I have a task that is done hundreds of thousands of times on a particular (large) buffer. I have measured that the performance is much better if I use threads for this task – the buffer is split into sub-buffers and each thread performs its task on the sub-buffer and returns the result. All the results from all threads are then added together, giving me the final solution.

However since this is done very often i’m losing precious time because of so many threads being created (because of the overhead that comes with thread creation). So i would like to have a pool of threads that would perform this task, instead of creating a new set of threads every time.

To be more clear, this is what i have so far:

  • Split the buffer into N sub-buffers of the same size
  • For each sub-buffer, create a thread and run it on the sub-buffer
  • Wait for all threads to complete (WaitForMultipleObjects), add together the results and destory the threads
  • Repeat

What i would like to achieve is this:

  • Split the buffer into N sub-buffers of the same size
  • Assign each sub-buffer to a thread from the threadpool (which has exactly N threads)
  • Once a thread finishes, let it sleep until another task is ready
  • When all threads are done (and sleeping) add together the results they produced
  • Repeat by waking up the threads and assign them new tasks

As you can see, this is a bit of a special thread pool, since i need to wait for the threads to finish. Basically i want to get rid of the overhead of creating threads all the time, since the program goes through hundreds of thousands of iterations so it can create&destroy milions of threads over its lifetime. Good news is that i do not need any synchronization at all between threads, they all get their own data and storage place fot the results. However i must wait until all threads are finished and i have the final solution, because the next task depends on the results of the previous task.

My main problem is with the management of threads:

  • how do i make my threads “sleep” and wake them up once new task is ready?
  • how do i wait for all the threads to finish?

I will be grateful for any help. Also feel free to ask questions if i was not clear enough. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:14:06+00:00Added an answer on May 31, 2026 at 1:14 am

    For me the preferred way for communicating with threads is via condition variables. Because you can define the needed condition and signal when it changes. In your case, you can combine it with a queue with which the sub-buffers are passed, so each thread waits while the queue is empty. The result can then be put on another queue where the managing queue is waiting until all threads have posted the result to the queue (the reference to this queue is passed as a request together with the sub-buffers).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.