My goal is to write a program that processes an arbitrary number of tasks based on user input.
Suppose that in this case the number of tasks is 1000.
Now I would like to have a dynamic number of threads that spawn and run tasks one at a time.
I would suggest that I need to use the "synchronous" method, as opposed to the "asynchronous" method, so if one task has a problem, I would not want it to slow down the completion of the rest.
What method would I use to accomplish the above? Semaphores? ThreadPools? And how can I make sure that the thread is not trying to start a task that is already being processed by another thread? Will “blocking” handle this?
Examples of code and / or links to sites that point to me in the right direction will be appreciated.
edit: The problem with the Fibonacci MSDN example is that the waitall method can handle up to 64 expectations. I need more than 1000 tasks. How to fix this situation without creating deadlocks?
source
share