// This is meCodeA framework implemented using the parallel_while loop.
Class body {
TBB: parallel_while <body> & my_while;
Public:
Body (TBB: parallel_while <body> & W): my_while (w ){}
//------------------------------------------------------------------------
// Following signatures required by parallel_while
//------------------------------------------------------------------------
Typedef long argument_type;
Void operator () (long c) const {
Function (c); // The function in this region is the part that needs to be implemented by yourself,
}
};
Class stream {
Id_queue_type & my_queue;
Public:
Stream (id_queue_type & _ Queue): my_queue (_ Queue ){}
Bool pop_if_present (Long & item ){
Return my_queue.pop_if_present (item );
}
};
Void parallelpreordertraversal (id_queue_type & _ Queue ){
TBB: parallel_while <body> W;
Stream S (_ Queue );
W. Run (_ queue, body (w ));
}
Void startalgrorithm ()
{
TBB: task_scheduler_init Init; // multi-thread Initialization
Parallelpreordertraversal (unbidpersonqueue );
}
Body stream parallelpreordertraversal. The three parts are the key to the while implementation. Body and stream are just a virtual function in the framework of parallel_while, it can be understood that parallel_while only provides us with a framework for converting loops into multi-threaded execution. However, we have to implement the specific implementation and reload it; this place is his subtlety, haha :)