Boost logo

Boost :

From: bill_kempf (williamkempf_at_[hidden])
Date: 2002-01-31 15:22:42


--- In boost_at_y..., "Rainer Deyke" <root_at_r...> wrote:
> ----- Original Message -----
> From: <Iain.Hanson_at_u...>
> To: <boost_at_y...>
> Sent: Thursday, January 31, 2002 12:23 PM
> Subject: Re: [boost] Re: mutex_traits<>
>
>
> >
> > Author: david.abrahams (david.abrahams_at_r...) at unix,mime
> > Date: 31/01/02 19:09
> >
> >
> > >...so you give newbies a "safe_mutex" on which scoped_lock works
> and for
> > >which there are no lock/unlock functions? Maybe I'm just getting
> hung up on
> > >the principle of the thing. After all, even experts are likely to
> use
> > >scoped_lock most often.
> >
> > One of the things that most concerns me with the totally safe
> interface is
> > that if I want to unlock the mutex early and then re-aquire it
later
> I
> > can't.
>
> {
> auto_ptr<scoped_lock> guard = new scoped_lock;
> // locked
> guard = 0;
> // unlocked
> guard = new scoped_lock;
> // locked again
> } // automatically unlocked as 'guard' leaves scope

Not very efficient, and most people on this list dislike having to
use dynamic allocation to do this. That's why there's built in
support for this today ;).

{
boost::mutex::scoped_lock lock(mutex);
// locked
lock.unlock();
// unlocked
lock.lock();
// locked again
} // automatically unlocked as 'lock' leaves scope


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk