Subj : Re: Improving read-write lock To : comp.programming.threads From : Joe Seigh Date : Fri Feb 18 2005 07:56 am On Thu, 17 Feb 2005 19:13:27 -0500, Joe Seigh wrote: > On Thu, 17 Feb 2005 22:03:30 GMT, Howard Hinnant wrote: > >> In article , >> "Joe Seigh" wrote: >> >> A::lock() instead could lock the mut_. But then you need a A::unlock() >> which might forget to be called (especially if an exception is thrown >> somewhere after the lock). > > You need to be careful about automatically unlocking locks for uncaught > exceptions. The lock should be unlocked if it can be determined that > no damages has occurred. Otherwise the lock should be left locked or > changed to damaged state. On further thought I don't think that dtors can detect whether an exception has been thrown, so a scoped lock dtor should put the lock into a damaged state if it's hasn't been unlocked by the current thread, and any attempt to use the lock after that should throw an exception. That's for write access locks. Read access locks can be unlocked in a dtor safely. IIRC, Java exceptions don't unlock monitor locks. Of course Java doesn't use dtors for scoping since it has GC. -- Joe Seigh .