ome task is performed in several consecutive stages. Each stage allows for
parallel processing by several working threads. A next stage may not be
attempted until all working threads finished processing of the current stage.
Such organization of processing is the service provided by the class
The precise procedure, performed on every stage, is supplied to the
ThreadMaster in form of a boost::function0<void> object (Called "Job" in
After a stage is finished but before the next stage is started the
ThreadMaster executes a boost::function0<bool> object on a single thread
and terminates if such execution returns "false". The
boost::function<bool> object is also supplied by the user. It is called
"Condition" in the code.
If at any stage the Job throws exception then such worker thread is restarted
and resumes from the same stage. If the operation of starting another thread
throws exception (thread number limits or memory problems) then the
ThreadMaster stops processing.
If the Condition throws exception then the ThreadMaster restarts the thread.
The newly started thread will execute the Job again and evaluate the Condition
If the given sequence of stages is exhausted then the ThreadMaster resumes the
same processing from the first stage.
The memory management of the ThreadMaster is similar to the management of the
boost::thread. The user may allocate ThreadMaster on stack or on heap. The
processing will continue until completion after the original ThreadMaster
instance is gone. The ThreadMaster has copy-by-value semantics. The copying
operation is light. All copies represent the same structure.