4fb Subj : Re: Futexes are wrong! (Are they?) To : comp.programming.threads From : David Schwartz Date : Tue Jun 07 2005 04:04 pm "Maciej Sobczak" wrote in message news:42a60d95$1_1@news.bluewin.ch... >> Easy. >> >> { >> scoped_lock h(mutex, condvar); >> // do stuff >> h.Unlock(); >> h.Signal(); >> } > > Which completely defeats the purpose of scoped_lock. No, it doesn't. The purpose of a scoped_lock is so that you do not have to put 'Unlock' calls before every 'return' and you can easily see where the lock is held and where it is not held. This preserves those features. > The above can be written in the following way with the same set of pros > and cons: > > { > mutex.lock(); > // do stuff > mutex.unlock(); > condvar.signal(); > } No, because in this case, you must call 'unlock' in every code path. > But I take the oppostunity to push your idea in the following direction: > > { > scoped_signalling_lock lock(mutex, condvar); > // do stuff > } > > The destructor of lock is supposed to do "the right thing". Yes, so long as you have a function like 'signal' the causes the lock to automatically signal after it's released. DS . 0