Intel® Threading Building Blocks (Intel® TBB) provides a wrapper around the platform's native threads, based upon the C++11 standard. Using this wrapper has two benefits:
It makes threaded code portable across platforms.
It eases later migration to ISO C++11 threads.
The library defines the wrapper in namespace std, not namespace tbb, as explained in Section Namespace.
The significant departures from C++11 are shown in the table below.
C++11 |
Intel TBB |
---|---|
template<class Rep, class Period> std::this_thread::sleep_for( const std::chrono::duration<Rep, Period>& rel_time) |
std::this_thread::sleep_for( const tbb::tick_count::interval_t& ) |
std::thread::id can be hashed with std::hash template class. |
std::thread::id can be hashed with tbb::tbb_hash_compare and tbb::tbb_hash template classes. |
rvalue reference parameters |
Parameter changed to plain value, or function removed, as appropriate. |
constructor for std::thread takes arbitrary number of arguments. |
constructor for std::thread takes 0-3 arguments. |
destructor for std::thread calls terminate(), if the thread is joinable(). |
destructor for std::thread calls detach(), if the thread is joinable(). |
The other changes are for compatibility with the C++03 standard or Intel TBB. For example, constructors that have an arbitrary number of arguments require the variadic template features of C++11.
Threads are heavy weight entities on most systems, and running too many threads on a system can seriously degrade performance. Consider using a task based solution instead if practical.