4,580 Posts served
11,094 Conversations started
- Academic

- Android

- Art, Music, & Animation

- Embedded Computing

- Events

- Game Development

- Graphics & Media

- Intel SW Partner Program

- Intel® AppUp Developer Program

- Manageability & Security

- Mobility

- Open Source

- Parallel Programming

- Performance and Optimization

- Power Efficiency

- Server

- Site News & Announcements

- Software Tools

- Ultrabook

- Association for Computing Machinery TechNews (ACM)
- Go Parallel! (Dr. Dobbs)
- HPCwire (Tabor Communications, Inc.)
- insideHPC (John West)
- Joe Duffy's Weblog (Microsoft)
- Microsoft Parallel Programming Development Center (Microsoft Germany)
- MultiCoreInfo.com
- scalability.org (Scalable Informatics)
- Software Dev Blog (Intel Germany)
- Soft Talk Blog (Intel United Kingdom)
- The Moth (Microsoft)
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: mutex, null_mutex, null_rw_mutex, TBB
For more complete information about compiler optimizations, see our Optimization Notice.


Dmitriy Vyukov
43,894
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; };