Link Copied
[cpp]// compute class task to process packet void PacketProcessTask(Packet_T* packet) { // may spawn multiple tasks // by using parallel_... templates // may include ArbitraryTask() below } // qtControl for I/O class task to write packet qtControl SocketWriteControl; // I/O class task to write packet void SocketWrite(Packet_T* packet) { // code to write to socket WriteToSocket(packet); // may wait for completion } // qtControl for I/O class task to read packets // until done or until fatal error qtControl SocketReadControl; // I/O class task to read packets // until done or until fatal error void SocketRead() { bool Done = False; while(!Done) { Packet_T* packet = ReadNextData(); // may wait for packet if(packet) { // schedule compute class task parallel_task(PacketTask, packet) } else { // check for recoverable error // or fatal error } } } // arbitrary compute class task // which includes enque of packet to SocketWrite I/O class thread void ArbitraryTask() { // code here // ... // now write packet using I/O class thread parallel_task(IO$, &SocketWriteControl, SocketWrite, packet); // code here // ... } // application int _tmain(int argc, _TCHAR* argv[]) { qtInit(-1, 3); // compute class = # HW threads // I/O class uses 3 threads // start "forever" SocketRead I/O class task parallel_task(IO$, &SocketReadControl, SocketRead); // While above runs // run parallel app code here // ...The TBB developers need to examine ways to resolve this issue. What is true above holds true for similar parallel programming requirements such as parallel_pipeline. The QuickThread implementation of parallel_pipeline makes use of both classes of thread pools. With occasional proding from others like me, the TBB development team will address this issue.
// end of program cleanup // Assure SocketRead task completed (with/without error) SocketReadControl.WaitTillDone(); // SocketWrite may have pending I/O SocketWriteControl.WaitTillDone(); return 0; } [/cpp]
For more complete information about compiler optimizations, see our Optimization Notice.