Boost logo

Boost Users :

Subject: [Boost-users] Priority task queues using Boost.Asio and Boost.Thread
From: Kelvin Chung (kelvSYC_at_[hidden])
Date: 2011-12-08 11:30:08


Suppose I have this abstract class Task like so:

struct Task {
        virtual int doStuff() = 0;
};

I then also have this:

class CompositeTask : public Task {
        std::vector<Task> tasks;
public:
        int doStuff() {
                for (std::vector<Task>::const_iterator it = tasks.begin(); it !=
tasks.end(); ++it) {
                        it->do_stuff();
                }
        }
};

Now suppose that there is a point where I have a list of Tasks and I
want to have them executed concurrently. To do so, I've leveraged
Boost.Asio to create a thread pool task queue construct (via
boost::asio::io_service). The next step beyond that is that I want to
evaluate each of the tasks in CompositeTasks in parallel. I have a few
questions about this:

* One idea is to make a separate task thread for each CompositeTask.
I'm under the impression that there is an absolute limit to the number
of threads that I can make, which is determined by
boost::thread::hardware_concurrency(). Is this true? If so, if the
main Task queue has that many threads, would making a second task queue
fail because it can't get more?
* If I keep to one task queue (ie. throw all the Tasks in the
CompositeTask to the main Task queue), then the possiblity exists of
some kind of starvation (eg. the queue is full of CompositeTasks, and
they are all blocking due to dependencies on Tasks in the queue). Is
there a way to prioritize Tasks in the queue so that this doesn't
happen?


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