Jeff Schwab
11/26/2008 4:10:00 PM
Rafael Cunha de Almeida wrote:
> I have some experience with pthreads in C and now I feel the need to
> use threads in C++. I suppose pthreads could work, but I'm sure there's
> a better way. Do you have suggestions of what I should use? I have a
> CPU intensive application that can be easily divided into threads, each
> thread will be very busy doing calculations and, as the end result, I
> expect a value out of each of the threads.
TBB (which Maxim suggested) is made for this. The Intel developers
refer to the management of individual threads as the "assembly language"
of concurrent programming, and provide a much higher-level,
task-oriented architecture with a respectably modern C++ interface. You
get your choice of free or commercial license.
If you just need a few extra threads for specific purposes (e.g. keeping
a GUI responsive, or waiting on a socket), Boost.Threads (as Boogie
suggested) should be fine. The upcoming C++ standard does include
standardized support for threads, which (AIUI) are similar to Boost
threads. Alternatively, wrapping pthreads in simple classes isn't too hard.