Boost logo

Boost :

From: Miki Jovanovic (miki_at_[hidden])
Date: 2000-03-07 17:57:52

"marco manfredini" <marc-_at_[hidden]> wrote:
> Could you point me where that 'call locking' is? I've looked up the
> smart-pointer classes from and did not find anything and
the issue
> isn't mentioned in the docs.
> It all looks like:
> T* operator->() const throw() { return px; }

I probably was not clear. We do not call it lock. I was thinking like

 - to lock means to guarantee object is not deleted
 - object is not deleted while refCount > 0
 - refCount > 0 while there is a smart pointer referencing the object

So a simple line like:

 - create another smart pointer to object to be locked

actually does accomplish your task.

In other words, creating another smart pointer to the object, locks it
for at least the life time of that smart pointer.

To be honest, I do not understand what you are trying to do with your
applied pointer.

You follow up with a lengthy discussion about a particular system
design taht encounters these problems. I probably sound too simplistic,
but with the 'locking' mentioned above, and with another rule: caller
must own the pointer to the callee, I have never faced this problem.

In partucular to your problem: mutuallu calling classes: If class A
calls class B, it must own the pointer to it. If class B calls A it
must own the pointer to A. Owning does not mean only owning the memory,
but also to manage access to it.

We both wrote examples:

My e.g.:
> > void doit()
> > {
> > _ptr<Worker> temp( w );
> > temp->work();
> > }
> >

Your e.g.:
> void doit()
> {
> _apply_ptr<Worker> t(w);
> t->work();
> }

How is this different? My way guarantees the lock without introducing a
new class, thus making the design simpler. What extra benefit do you
get from _apply_ptr?

> apply_scoped_ptr<A> foreign;
> void doit()
> {
> scoped_ptr<A> sa(new A);
> {
> apply_scoped_ptr<A> asa(sa);
> //use it..
> }
> scoped_ptr tsa(new A);
> sa=tsa; // safe, because no more in use.

> apply_scoped_ptr<A> asa(sa);
> foreign=asa; // foreign has a lifetime that is not a subset of sa's
> liefetime - this may be a problem! anyway allowed.
> }

You seem to be missing the point here. If you replaced all of the
pointers above with smart pointers, you would get *completely* safe
code. It does not matter how many times you copy it, pass it as a
parameter or use it otherwise, as long as you have your smart pointer
to something you can use it.



Boost list run by bdawes at, gregod at, cpdaniel at, john at