Boost logo

Boost Users :

Subject: [Boost-users] [signals2] tracking intrusively ref-counted object
From: Igor R (boost.lists_at_[hidden])
Date: 2009-09-05 19:01:48


Hello,

In my project I've got intrusively ref.counted objects (particularly,
ATL COM-objects), which listen to signals of some asynchronous
subsystem. Currently, when these objects connect to the signals, they
bind their own intrusive smart-ptrs to the slot functor, like this:
// pseudo code
Object::init()
{
  asyncSubsystem_.onSignal_.connect(bind(&Object::handleSignal,
intrusive_from_this...)); // ensure the slot wouldn't bound to a dead
object
}

Of course, this implies that the object cannot "die" until it's
explicitly disconnected from the signal, so when the user of my
library wants to get rid of such an object, he must call one more
function (say, obj->close()) before resetting his smart-ptr to the
object -- which is not just inconvenient, but also threatens the
exception safety of user's code.

Now I'd like to eliminate the need for this additional "finalization".
For this purpose I have to:
a) bind plain "this" to the slot functor -- so that the signal
wouldn't be a "strong" client of Object
b) eliminate race condition between slot invocation (coming from
asyncSubsystem's thread) and the destruction of Object caused by
resetting of user's intrusive ptr

I tried to think of different ways to solve (b), but nothing seems to
work so far... So my question is whether (b) is ever possible, and
what would be the right solution for the whole issue.

Thank you,

Igor'.


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