MeshLib C++ Docs
Loading...
Searching...
No Matches
MR::TbbThreadMutex Class Reference

#include <MRTbbThreadMutex.h>

Classes

class  LockGuard
 RAII-style lock guard for the mutex; releases it on destruction. More...
 

Public Member Functions

MRMESH_API TbbThreadMutex (std::thread::id id=std::this_thread::get_id())
 
MRMESH_API std::optional< LockGuardtryLock ()
 

Detailed Description

helper class used to ensure that the specific thread is not re-used by TBB use it if you have nested TBB operations (e.g. parallel_for inside another parallel_for)

TbbThreadMutex reportThreadMutex;
tbb::parallel_for( range, [&] ( auto&& range )
{
const auto reportThreadLock = reportThreadMutex.tryLock();
for ( auto i = range.begin(); i != range.end(); ++i )
{
// if you have a nested `parallel_for` call here, you might come back to the same main loop with another range
// since TBB can re-use 'stale' threads
tbb::parallel_for( ... );
if ( reportThreadLock )
report( ... );
}
} );
Definition MRTbbThreadMutex.h:32
MRMESH_API std::optional< LockGuard > tryLock()

Constructor & Destructor Documentation

◆ TbbThreadMutex()

MRMESH_API MR::TbbThreadMutex::TbbThreadMutex ( std::thread::id id = std::this_thread::get_id())
explicit

construct class

Parameters
id- id of thread allowed to lock the mutex

Member Function Documentation

◆ tryLock()

MRMESH_API std::optional< LockGuard > MR::TbbThreadMutex::tryLock ( )

try to lock the mutex returns a lock guard if the current thread id is equal to the mutex's one and the mutex is not locked yet


The documentation for this class was generated from the following file: