Intel® oneAPI Threading Building Blocks (oneTBB)
Mutexes
Intel® oneAPI Threading Building Blocks (oneTBB)
MutexesWith
Intel® oneAPI Threading Building Blocks (oneTBB)
, you can associate a
mutex
with a shared object to enforce mutually exclusive access to that object. A mutex is either locked or unlocked. For a thread to safely access the object:
- The threadacquires a lockon the mutex.
- The thread accesses the associated shared object.
- The threadreleases its lockon the mutex.
When a mutex is locked, if another thread tries to also acquire a lock on it, this second thread is stalled until the first thread releases its lock on the mutex. This functionality provided by a mutex is exactly the semantic function intended by the
Intel Advisor
annotations
ANNOTATE_LOCK_ACQUIRE()
and
ANNOTATE_LOCK_RELEASE()
.
With
oneTBB
, the annotation lock address becomes the mutex object. The
ANNOTATE_LOCK_ACQUIRE()
and
ANNOTATE_LOCK_RELEASE()
annotations become operations on this mutex.
oneTBB
provides several classes for locking, each with different properties. For more information, refer to the
oneTBB
documentation. If you are not sure what type of a mutex is most appropriate, consider using
tbb::mutex
as your initial choice.