Boost logo

Boost Users :

Subject: Re: [Boost-users] [signals2] tracking intrusively ref-counted object
From: Igor R (boost.lists_at_[hidden])
Date: 2009-09-06 09:03:30


> If you can access the value of the reference count, you could have your slot check to see if the reference count has dropped to 1

Actually, you mean I have to override object's release() method -- as
this's the only piece of code that knows when ref.count drops to 1.
I'm still not sure I understand how to make this solution thread-safe.
Lets consider the following scheme:

struct object
{
  void init()
  {
    selfAncor_ = some_intrusive_ptr<object>(this);
    connection1_ = signal1_.connect(&handle, ref(selfAncor_));
    connection2_ = signal2_.connect(&handle, ref(selfAncor_));
  }

  int release()
  {
    do_release();
    if (refcount_ == 1)
    {
      connection1_.disconnect();
      connection2_.disconnect();
      // the following line is unsafe, because some slot invocation
might be in progress!
      selfAncor_.reset();
    }
  }

};

Thanks!


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net