Boost Users :
From: Torsten Mohr (tmohr_at_[hidden])
Date: 2007-10-01 18:30:39
i have a question regarding boost::thread on general usage.
I have a calculation intense problem that can be parallelised quite well.
But i'd like the whole thing to be interruptible, so when the user commands
to stop calculationg then the threads should stop working on the problem.
I don't know how to set this up in principle, some thoughts:
I want to create one manager thread and several worker threads.
The manager thread commands the worker threads on what job to work.
When a worker thread has finished, it tells the manager thread so
and can get another job to work on.
If a user commands the manager thread to stop working, the manager
thread commands the worker threads to stop as soon as possible.
I think these are quite some normal requirements, but i don't know
how to implement this using boost::thread.
What is the preferred way to send commands to threads? Just lock
a mutex that is shared with the thread and then write a shared variable?
How can a manager thread wait on several worker threads at once without
wasting CPU time? How does a worker thread notify the manager thread?
I can't see how this can be done with boost::condition, do i miss something?
Or is it possible for the worker thread to share a boost::mutex with every
worker thread, let the manager thread lock those mutexes? It then can
only do "condition->wait" on _one_ of the conditions.
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