Recently, I was tasked with writing a multi-threaded C++ sample application as a way of highlighting Intel’s multi-core processors. I decided to write a file compression program that compresses the contents of a specified directory branch. Once the branch to compress is specified, the processing can be broken down into 3 clearly defined sub tasks: file scrub and input, block compression, and output to the compressed file. I envisioned each of these tasks running in its own thread, with thread-safe queues to pass intermediate work between them. Of the code I had to write, the trickiest, I thought, would be the 2 queues.
Before I finished coding the application, a new requirement was added to the project. Intel has released a new C++ runtime library called “Threading Building Blocks.” I was asked to use this library in the sample application. So I downloaded an evaluation version of TBB from here, and headed back to the design board.
TBB comes with great documentation, including a “Getting Started” guide, a “Tutorial” that goes into more depth, and an exhaustive reference guide. I read the tutorial first, which gave me all I needed for my purposes. TBB offers support for several threading paradigms, including loop parallelization, task pipelining, thread-safe containers, and much more. The TBB pipeline was the best choice for what I was doing. I put each task in its own C++ class, registered the classes with the pipeline, and let it run. The best part was that I didn’t need to write the queues; TBB provided for passing the intermediate data between tasks.
I must say that dealing with the Threading Building Blocks was an unexpected pleasure. My experience using software tools for the first time has been a mixed bag at best; it’s often extremely frustrating to understand and utilize these tools quickly. For instance, the public-domain compression engine I originally intended to use cost me hours of configuration and building headaches, and I never did get it to build in a way that I could use. I ended up tossing it out and using a different compression engine altogether. TBB on the other hand was well documented, easy to understand and implement, and worked right out of the box. I must say that the next time I need to write a C++ application using multiple threads, I’ll likely reach for TBB.
The sample application, along with a readme file that does into the TBB code in some depth, can be found here.
Richard Bowler
rbowler@3leaf.com
Hi. I've just started using TBB myself. I must say I like the approach, but I'm skeptical of the concurrent_* containers among other things.
Since you wrote this post a year ago, I'm wondering, how has your experience with TBB been lately. Is it worth persevering for bigger projects?
Posted by: Gomez | September 27, 2007 at 09:31 AM
Have you tried running multiple pipelines in parallel using parallel_for? I am asking because I have tried this and I am facing a crash which I haven't been able to debug.
Posted by: Aaron | August 18, 2009 at 11:40 PM
Blogs are so informative where we get lots of information on any topic. Nice job keep it up!!
Posted by: HR Dissertation | November 04, 2009 at 06:53 AM