Simulating do-nothing mutexes -- null_mutex and null_rw_mutex

By Wooyoung Kim (Intel) (6 posts) on September 28, 2009 at 11:16 am

Early this year a TBB user requested in the forum for the feature that simulates mutexes that do nothing. The user wrote “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...[snip]... If we can have a NullMutex feature ... it would be easy to handle such situations.”
(http://software.intel.com/en-us/forums/intel-threading-building-blocks/topic/63003/). We agreed and thought the idea made sense, and added null_mutex and null_rw_mutex to Intel® Threading Building Blocks's mutex lineup. (They have been available since Intel® TBB 2.1 Update 3 and officially added to Intel® TBB 2.2). Both mutexes were built based on Alexey Kukanov's sketch posted in the forum. As Alexey noted, their is_recursive and is_fair traits are set to true. The two mutexes really do nothing and simulate successful mutex operations. I hope this answers the question about the status posted here (http://software.intel.com/en-us/forums/intel-threading-building-blocks/topic/66231/reply/86944/).

Categories: Software Tools
Tags: , , ,

For more complete information about compiler optimizations, see our Optimization Notice.

Comments (1)

September 29, 2009 4:01 AM PDT

Dmitriy Vyukov
Dmitriy VyukovTotal Points:
43,894
Black Belt
Why do you need 2 different null mutexes? IMO one really do not need all those rw/spin/fair/distributed/etc variations for null mutex. One just needs single interface superset that will be able to be compiled successfully in all situations.
Something like:
class null_mutex {   
    null_mutex( const null_mutex& );   
    void operator=( const null_mutex& );   
public:   
    class scoped_lock {   
    public:   
        scoped_lock() {}
        scoped_lock( null_mutex& , bool = true) {}   
        ~scoped_lock() {}
        void acquire( null_mutex& , bool = true) {}
        bool try_acquire( null_mutex& , bool = true) { return true; }
        void release() {}
        bool upgrade_to_writer() { return true; }
        bool downgrade_to_reader() { return true; }
    };
  
    null_mutex() {}
    
    // Mutex traits   
    static const bool is_rw_mutex = true;   
    static const bool is_recursive_mutex = true;
    static const bool is_fair_mutex = true;
};  

Trackbacks (0)


Leave a comment  

To obtain technical support, please go to Software Support.
Name (required)*

Email (required; will not be displayed on this page)*

Your URL (optional)


Comment*