Boost logo

Boost :

Subject: Re: [boost] [smart_ptr] shared_ptr template type
From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2009-07-09 14:27:22


On Thursday, July 9, 2009, Frank Mori Hess <frank.hess_at_[hidden]> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>
> I wonder if it might be better/possible to have a shared_ptr<T> that didn't
> assume its corresponding "raw" pointer type was T* but rather T.  For
> example, what is now a shared_ptr<int> would be specified as a
> shared_ptr<int*>.  The motivation would be to allow support for other classes
> as the "raw" pointer type.  For example, I might want to have a
> shared_ptr<monitor<T*> > where the monitor<T*> has an operator->() which does
> automatic locking/unlocking of a mutex before/after forwarding the
> operator->() to the plain T pointer.

I don't think lock/unlock on each -> call is typically a good idea.
 x = p->x;
 y = p->y;
That's 2 lock unlock sequences instead of one. Inefficient and what
if y changes after you read x?
It hides the locking too much, potentially leading to abuse and mistakes.

I think alexandrescu has an article about this somewhere. (he also has
articles about how to implement locking -> operators but I think he
later recanted on the whole idea)

Tony


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