Author: Du Wei
Intel thread building module (Intel TBB) is the most well-known C ++ thread library. Its latest version has been updated to 4.2. Compared with earlier versions 4.1, the updated version provides multiple important new features. Some features have been released in TBB 4.1 update.
The new synchronization primitive speculative_spin_mutex provides support for speculative locking. This makes it possible to use Intel (R) transactional synchronization extensions (Intel TSX) hardware features on the 4th-generation Intel core processor. As long as there is no "Conflict" that may lead to a different result from the non-speculative lock, it is assumed that the mutex lock supports hardware transactional memory (such as Intel TSX) when working on the processor, multiple threads are allowed to obtain the same lock. Therefore, no serialization will occur in non-competitive cases. In this way, the performance and scalability can be greatly improved in the key areas of "short. If hardware support is not provided for transactional synchronization, it is assumed that the role of the mutex lock is similar to that of the non-speculative mutex lock, and it is likely to show worse performance.
Intel TBB now supports accurate Exception Propagation Features (based on C ++ 11 exception_ptr ). With exception_ptr, exception objects can be securely copied between threads. This provides flexibility for exception handling in multi-threaded environments. Currently, accurate Exception Propagation is available in pre-built libraries on all platforms, such as OS X *, Windows *, and Linux *. There are two types of libraries on OS X *: The first library is associated with the gcc standard library-by default, this library does not support accurate Exception Propagation. To use this feature, you should use the second library associated with libc ++ (C ++ standard library in Clang. To use these features, first create an Intel TBB environment and then build your application as follows:
# tbbvars.sh libc++
# clang++ -stdlib=libc++ -std=c++11 concurrent_code.cpp -ltbb
In addition to the concurrent_unordered_set and concurrent_unordered_map containers, we now provide the concurrent_unordered_multiset and concurrent_unordered_multimap containers based on the Microsoft * PPL prototype. With concurrent_unordered_multiset, you can insert an item multiple times, which is impossible in concurrent_unordered_set. Similarly, concurrent_unordered_multimap allows you to insert more than one <key, value> pair with the same key value. In the case of a "multiple" container, find returns the first (or <key, value> pair) in a table with a matching search key ).
The Intel TBB container can now use the Value List specified by C ++ 11 (the initialization program list) for convenient initialization:
1 |
tbb::concurrent_vector<int> v ({1,2,3,4,5} ); |
Currently, the following containers support initialization program list:
Concurrent_vector
Concurrent_hash_map
Concurrent_unordered_set
Concurrent_unordered_multiset
Concurrent_unordered_map
Concurrent_unordered_multimap
Concurrent_priority_queue
The Scalable Memory Allocation program provides high-speed cache for the allocated memory in each thread. Although this method ensures performance, it usually increases the memory usage. Although the memory allocation program tries its best to avoid excessive memory usage, Intel TBB 4.2 still gives more control in complex circumstances to the programmer: Now you can use scalable_allocation_command () function cleanup threads cache at high speed to reduce memory consumption. This also helps greatly improve the overall performance of the allocation program.
The Intel TBB library has been widely used on a variety of platforms. Mobile developers can now find pre-built binary files suitable for Android in the Linux * Operating System package. The binary file of the Windows Store * application has been added to the Windows * Operating System package.
Atomic variable tbb: atomic <T> the constructor is available in C ++ 11. This allows programmers to initialize their values when declaring them, and correctly supports constructing expressions. In this case, the following code is valid for the gcc and Clang compilers:
The new Community preview feature allows waiting until all worker threads terminate. This situation may be necessary when applications break down processes; otherwise, the TBB dynamic library may be detached from the runtime (for example, if TBB is part of a plug-in ). To enable the workthread wait function, initialize the task_scheduler_init object as follows:
1 |
#define TBB_PREVIEW_WAITING_FOR_WORKERS 1 |
2 |
tbb::task_scheduler_init scheduler_obj (threads, 0, /*wait_workers=*/true); |
About the latest intel TBB 4.2 Website: commercial and open-source. Download and start using new features!