Boost logo

Boost :

From: bill_kempf (williamkempf_at_[hidden])
Date: 2002-01-31 16:06:41


--- In boost_at_y..., "Peter Dimov" <pdimov_at_m...> wrote:
> From: "bill_kempf" <williamkempf_at_h...>
> > I think you misunderstand me here. A lock_ptr<> is not a thread
safe
> > shared_ptr<>, it's a completely new smart pointer that uses a
proxy
> > class to lock a mutex before accessing the object through
operator->
> > and unlock the mutex afterwards. It's an idea presented by Bjarne
> > Stroustrup, and it's very difficult to implement using only a
Scoped
> > Lock.
>
> A scoped lock works fine:

[snipped code]

It only works because you've removed the scoped nature by allocating
the lock on the heap. There are numerous reasons why people dislike
having to use dynamic allocation in order to implement things like
this, and in general I think they are correct. In the early days of
the mutex design this was brought up with the concern for
handling "overlapping locks" and I argued for dynamic allocation
then. I was subsequently convinced that this wasn't good enough and
added the lock/ulock methods to the Scoped Lock to address this.
However, that only helps with "overlapping locks" and doesn't really
help in cases such as lock_ptr<>.

Bill Kempf


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