
Howard Hinnant wrote:
I don't dislike these helper functions. But I do dislike the idea that they should be the only way to construct-and-try or construct-with-time. The problem is that we have 3 different types of locks, and I want to be able to construct-and-try in a generic-lock function:
template <class Lock> void foo() { Lock lk(m, try_lock); ... }
The above code should work for scoped_lock, sharable_lock and upgradable_lock.
template<class Lock> void foo() { bool const deferred = false; Lock lock( m, deferred ); if( lock.try_lock() ) { // locked } } as usual. Clean separation between lock type (scoped/exclusive, shareable, upgradable) and lock operations (unconditional blocking lock, try lock, timed lock, unlock).