Boost logo

Boost Users :

Subject: Re: [Boost-users] [Threads] How to keep number of running thread constant, performing different operations
From: Brad Howes (bradley.howes_at_[hidden])
Date: 2011-06-17 03:46:06


On Jun 17, 2011, at 9:05 AM, Alessandro Candini wrote:

> I have different threads which have to work on completely different input and output data (non critical sections): an atomic operation per thread, each one with different time execution but everyone with an intense use of the CPU.
> Let's say I have 10 operations to perform (10 threads): I would like to run concurrently only 2 threads because of resource consumption.
>
> My problem is that when a threads ends its execution, I would like to suddenly start another thread performing operation 3, in order to have constantly 2 threads working, and so on until the end of operations.
>
> How can I achieve this? I thought to insert my threads into a vector...but I have no idea on how start and join them in order to obtain what described above.

Look into consumer/producer (http://en.wikipedia.org/wiki/Producer-consumer_problem). At the end of processing, a thread would then add a new work request to the appropriate work queue so that processing of the next stage would commence when a thread is available to do it.

Brad

-- 
Brad Howes
Calling Team - Skype Prague
Skype: br.howes

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net