Boost logo

Boost :

From: Miki Jovanovic (miki_at_[hidden])
Date: 2000-03-07 14:21:34


"marco manfredini" <marc-_at_[hidden]> wrote:
> void doit()
> {
> w->work();
> }

> I've looked at the smart-pointer classes in boost, but I found no
provisions
> to guard the 'this' Pointer that lurks
> around during a call. However, the pattern I am describing is to be
expected
> in complex object interactions and
> will produce these randomly appearing bugs, that shorten a developers
> lifespan.

> A -transparent- solution is to create an extra lock during a call.
(i.e
> operator-> returns a temporary): This has implications to
> the performance of the various pointer classes, which need to be
> investigated.
> Workarounds are possible, but they all look very error prone to me.

Hi Marco,

Complicated e-mail, and complicated code, for a simple question. All
smart pointers out there do provide a 'locking' mechanism as you call
it. And that is a temporary pointer, which you have actually mentioned.

Difference is, pointers do not deal with temporaries by default because
of the performance hit. Also your problem of two way referencing of two
classes is also not very common, and such dependencies should be
avoided whenever possible.

So your code should simply become:

  void doit()
    {
      _ptr<Worker> temp( w );
      temp->work();
    }

And this kind of protection is needed only in mutually referencing
classes.

Cheers,

Miki.


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