Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

Request For NullMutex Feature

ksgokul
Beginner
467 Views
Hi,
Lot of times, when we do template meta programming, we need to provide some containers with no mutex( tbb containers ) and some containers with a tbb Mutex (Boost /std containers). The Scoped Lock feature makes the code different for both. If we can have a NullMutex feature like the one available in ACE( ACE_Null_Mutex), it would be easy to handle such situations. Please advise me on any work arounds currently available.This NullMutex is more like a no-op.

Thanks in advance,
Gokul.
0 Kudos
1 Solution
Alexey-Kukanov
Employee
467 Views
If you only use scoped lock pattern (i.e. no explicit calls to acquire/release), the following should work:
[cpp]class null_mutex {
    //! Deny assignment and copy construction
null_mutex( const null_mutex& ); void operator=( const null_mutex& ); public: class scoped_lock { public: scoped_lock( null_mutex& ) {} ~scoped_lock() { } }; // Mutex traits static const bool is_rw_mutex = false; static const bool is_recursive_mutex = false; static const bool is_fair_mutex = false; }; [/cpp]

Anyway the idea is reasonable. Thanks for the suggestion.

View solution in original post

0 Kudos
4 Replies
Alexey-Kukanov
Employee
468 Views
If you only use scoped lock pattern (i.e. no explicit calls to acquire/release), the following should work:
[cpp]class null_mutex {
    //! Deny assignment and copy construction
null_mutex( const null_mutex& ); void operator=( const null_mutex& ); public: class scoped_lock { public: scoped_lock( null_mutex& ) {} ~scoped_lock() { } }; // Mutex traits static const bool is_rw_mutex = false; static const bool is_recursive_mutex = false; static const bool is_fair_mutex = false; }; [/cpp]

Anyway the idea is reasonable. Thanks for the suggestion.
0 Kudos
ksgokul
Beginner
467 Views
If you only use scoped lock pattern (i.e. no explicit calls to acquire/release), the following should work:
[cpp]class null_mutex {
//! Deny assignment and copy construction
null_mutex( const null_mutex& );
void operator=( const null_mutex& );
public:
class scoped_lock {
public:
scoped_lock( null_mutex& ) {}
~scoped_lock() { }
};

// Mutex traits
static const bool is_rw_mutex = false;
static const bool is_recursive_mutex = false;
static const bool is_fair_mutex = false;
};
[/cpp]

Anyway the idea is reasonable. Thanks for the suggestion.
Thanks for the Solution..

Gokul.
0 Kudos
Alexey-Kukanov
Employee
467 Views
We willmake an extended version of it part of TBB.

Also during the internal discussion, it was suggested that is_recursive and is_fair traits should be true for null_mutex.
0 Kudos
ksgokul
Beginner
467 Views
We willmake an extended version of it part of TBB.

Also during the internal discussion, it was suggested that is_recursive and is_fair traits should be true for null_mutex.
Great to hear that the request has been accepted. I will update the static variables accordingly. Actually the new values make a lot of sense.
0 Kudos
Reply