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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:30:42+00:00 2026-05-12T12:30:42+00:00

My goal is to write a program that handles an arbitrary number of tasks

  • 0

My goal is to write a program that handles an arbitrary number of tasks based on given user input.

Let’s say the # of tasks are 1000 in this case.

Now, I’d like to be able to have a dynamic number of threads that are spawned and start handling the tasks one by one.

I would assume I need to use a “synchronous” method, as opposed to a “asynchronous” one, so that in case one tasks has a problem, I wouldn’t want it to slow down the completion of the rest.

What method would I use to accomplish the above? Semaphores? ThreadPools? And how do I make sure that a thread does not try to start a task that is already being handled by another thread? Would a “lock” handle this?

Code examples and/or links to sites that will point me in the right direction will be appreciated.

edit: The problem with the MSDN Fibonacci example is that the waitall method can only handle up to 64 waits. I need more than that due to the 1000 tasks. How to fix that situation without creating deadlocks?

  • 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-12T12:30:42+00:00Added an answer on May 12, 2026 at 12:30 pm

    Are these tasks independent? If so, you basically want a producer/consumer queue or a custom threadpool, which are effectively different views on the same thing. You need to be able to place tasks in a queue, and have multiple threads be able to read from that queue.

    I have a custom threadpool in MiscUtil or there’s a simple (nongeneric due to age) producer/consumer queue in my threading tutorial (about half way down this page).

    If these tasks are reasonably long-running, I wouldn’t use the system threadpool for this – it will spawn more threads than you probably want. If you’re using .NET 4.0 beta 1 you could use Parallel Extensions though.

    I’m not quite sure about your comment on WaitAll… are you trying to work out when everything’s finished? In the producer/consumer queue case, that would probably involve having some sort of “stop” entry in the queue (e.g. null references which the consuming threads would understand to mean “quit”) and then add a “WaitUntilEmpty” method (which should be fairly easy to implement). Note that you wouldn’t need to wait until the last items had been processed, as they’d all be stop signals… by the time the queue has emptied, all the real work items will definitely have been processed anyway.

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

Sidebar

Related Questions

My final goal is to write the program which can run on the Unix
my goal is to write a stored proc that can collect all field values
I am trying to write a cross-platform python program that would run in the
I have a program (that I did not write) which is not designed to
I wanted to write a makefile for a program that has source files located
My objective is to write a program that can create folders and within those
I want to write a ruby program that could inspect the variable value of
The goal behind this question is to create a portable Windows script/program that would
I am trying to write a program in python or c that can debug
So the goal is that the tablet can read and write a value of

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.