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 7637191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:52:36+00:00 2026-05-31T07:52:36+00:00

I have N tasks, which are independent (ie., write at different memory addresses) but

  • 0

I have N tasks, which are independent (ie., write at different memory addresses) but don’t take exactly the same time to complete (from 2 to 10 seconds, say). I have P threads.

I can divide my N tasks into P threads, and launch my threads. Ultimately, at the end, there will be a single thread remaining to complete the last few tasks, which is not optimal.

I can also launch P threads with 1 task each, WaitForMultipleObjects, and relaunch P threads etc. (that’s what I currently do, as the overhead of creating threads is small compared to the task). However, this does not solve the problem either, there will still be P-1 threads waiting for the last one at some point.

Is there a way to launch threads, and as soon as the thread has finished its task, go on to the next available task until all tasks are completed ?

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-31T07:52:37+00:00Added an answer on May 31, 2026 at 7:52 am

    yes, it’s called thread pooling. it’s a very common practice.

    http://en.wikipedia.org/wiki/Thread_pool_pattern

    Basically, you create a queue of tasks (function pointers with their arguments), and push the tasks there. You have N threads running which do the following loop (schematic code):

    while (bRunning) {
       task = m_pQueue.pop();
       if (task) {
          executeTask(task);
       }
       else {
        //you can sleep a bit here if you want
       } 
    }
    

    there are more elegant ways to implement it (avoiding sleeps, etc) but this is the gist of it.

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

Sidebar

Related Questions

I have an application which performs 30 independent tasks simultaneously using multithreading, each task
I have three tables, one is tasks which are tasks that factory workers complete
I am using Ruby (1.9.3) and Rails (3.2.2). I have tasks file which contains
I have a table called TPM_TASKS which contain all tasks, as well as a
I have got a pipeline of tasks which basically is a variation of chain
I have a tasks table with a priority column, which has a unique constraint.
I have an android application in which I have to execute some tasks at
Lets suppose I have a RESTful service which has a list of tasks. GET
I have a service responsible for many tasks, one of which is to launch
I have a regression model in which the dependent variable is continuous but ninety

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.