Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
6 Views

Request For NullMutex Feature

Jump to solution
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

Accepted Solutions
Highlighted
6 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
Highlighted
7 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
Highlighted
Beginner
6 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
Highlighted
6 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
Highlighted
Beginner
6 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