
Peter Dimov wrote:
compare:
TryLock l( m, unlocked );
if( l.try_lock() ) { }
with:
TryLock l( m, non_blocking );
if( l.locked() ) { }
(Jumping late, forgive me if this has been discussed already.) How about: if( ScopedLock l = try_lock( m ) ) { } where try_lock is function that returns a simple wrapper class: template< Mutex > struct try_locker { Mutex & m; ... }; template< Mutex > try_locker< Mutex > try_lock( Mutex & m ) { return try_locker< Mutex >( m ); }; and ScopedLock is some lockable type which has a constructor that accepts a try_locker. (It would also need a bool-ish conversion to allow the lock to be declared in the "if" statement, but that's not relevant to this discussion.) -- Eric Niebler Boost Consulting www.boost-consulting.com