Is there an equivalent to boost::interprocess::null_mutex in C++11 (e.g. std::null_mutex)?
c++, c++11, mutex
Solution
You can make this fairly trivially, by creating a 'null' implementation of the `Lockable` concept:
struct null_mutex
{
void lock() {}
void unlock() noexcept {}
bool try_lock() { return true; }
};
This would work with std::lock_guard:
null_mutex mux;
std::lock_guard<null_mutex> guard(mux);
Problem
I find the ability to drop in a `null_mutex` (currently `boost::interprocess::null_mutex`) very useful when I don't want the synchronization overhead in some cases and a real mutex in others. I am trying to use the new c++11 `mutex` classes, but I see no equivalent for `null_mutex` - which leaves me puzzled.. Yes I know it's trivial to implement (or I can continue to use boost, but where possible I'm trying to stick the standard and seems like a small omission?)