Subj : Re: Improving read-write lock To : comp.programming.threads From : Marcin 'Qrczak' Kowalczyk Date : Thu Feb 24 2005 07:18 pm "Joe Seigh" writes: >>> Given that there seem to be an awful lot of programmers that think that >>> locks should be unlocked on exceptions, I doubt sensible implementations >>> are the rule. >> >> Why do you think leaving the lock locked would be a better default? >> > You need to explicitly ensure the shared data is in a valid state. This should be done by letting the exception to be thrown only when the shared state is valid, not by trying to recover afterwards which would not be reliable. If the program throws further than the point of taking the lock when the state is valid (maybe it was only reading the shared state), the mutex should better be unlocked. If it throws when the state is not valid, the program is most probably buggy and deadlocking the application doesn't help - the program should be fixed anyhow. -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/ .