Forum Jump

Select Group :
Select Forum :
Sorted By :
Sort Order :
From The :
 
Thread Tools  Search this thread 
ksgokul
Total Points:
145
Status Points:
0
Green Belt
January 17, 2009 7:32 AM PST
Request For NullMutex Feature
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.
Alexey Kukanov (Intel)
Total Points:
13,396
Status Points:
13,396
Black Belt
January 17, 2009 3:46 PM PST
Rate
 
|Best Answer
#1
If you only use scoped lock pattern (i.e. no explicit calls to acquire/release), the following should work:
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; };

Anyway the idea is reasonable. Thanks for the suggestion.


ksgokul
Total Points:
145
Status Points:
0
Green Belt
January 20, 2009 5:27 AM PST
Rate
 
#2 Reply to #1
If you only use scoped lock pattern (i.e. no explicit calls to acquire/release), the following should work:
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;
};

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

Gokul.


Alexey Kukanov (Intel)
Total Points:
13,396
Status Points:
13,396
Black Belt
January 20, 2009 8:49 AM PST
Rate
 
#3 Reply to #2
We will make 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.


ksgokul
Total Points:
145
Status Points:
0
Green Belt
January 23, 2009 5:10 AM PST
Rate
 
#4 Reply to #3
We will make 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.




Intel Software Network Forums Statistics

8487 users have contributed to 31622 threads and 100698 posts to date.
In the past 24 hours, we have 35 new thread(s) 121 new posts(s), and 186 new user(s).

In the past 3 days, the most popular thread for everyone has been gemm(A,A,A) like possible? The most posts were made to gemm(A,A,A) like possible? The post with the most views is Dear Steve, excuse me for a d

Please welcome our newest member chat1983