Subj : Re: Lockable objects To : comp.programming.threads From : Peter Dimov Date : Sat May 21 2005 04:06 pm Uenal Mutlu wrote: > You said it: diagnostics, and debug. > Esp. in such situations like below: > > void f() > { // requires that object must be locked before calling this func > > #ifndef NDEBUG > assert(!m.IsLocked()); > #endif > > //... > } This makes sense as long as IsLocked() only returns true if the current thread is the one holding the lock. This in effect requires an owner field. Another approach that works on application level is to enforce the use of lock classes (such as boost::scoped_lock) and pass such a lock to f. void f( scoped_lock & lock ) { assert( lock.locked() ); assert( lock.mutex() == &m ); // ... } .