[boost-users][signals2] thread-safe disconnection for intrusively ref-counted objects
Hello, Is there any trick or customization that would allow the subj? I mean the following situation: // pseudo-code! class intrusively_refcounted : //... { private: void listenToAsyncSubsystem() { // signals will come from another thread asyncSubsystem_.someEvent.connect(slot_type(&intrusively_refcounted::handler, this).track(???)); // can't use here shared_ptr/weak_ptr for tracking } }; I could store a connection object, so that it would be destroyed/disconnected in ~intrusively_refcounted(), but I guess it's not thread-safe, just like the approach with "trackable". So what would be the correct approach? Thanks!
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday 12 May 2009, Igor R wrote:
// pseudo-code! class intrusively_refcounted : //... { private: void listenToAsyncSubsystem() { // signals will come from another thread
asyncSubsystem_.someEvent.connect(slot_type(&intrusively_refcounted::handle r, this).track(???)); // can't use here shared_ptr/weak_ptr for tracking } };
I could store a connection object, so that it would be destroyed/disconnected in ~intrusively_refcounted(), but I guess it's not thread-safe, just like the approach with "trackable".
So what would be the correct approach?
Could you implement intrusively_refcounted with a pimpl owned by a shared_ptr? So a group of equivalent intrusively_refcounted objects might share a single dynamically allocated shared_ptr which the delete when the refcount hits zero, and it could also be used to obtain a weak_ptr for tracking. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkoJyPwACgkQ5vihyNWuA4VicwCfU4tAlsF8Ntzovnw3pmmO6KC0 CBkAoOJntq+SYKQDjR4pbFE7jK5lqTZk =hnpz -----END PGP SIGNATURE-----
Could you implement intrusively_refcounted with a pimpl owned by a shared_ptr? So a group of equivalent intrusively_refcounted objects might share a single dynamically allocated shared_ptr which the delete when the refcount hits zero, and it could also be used to obtain a weak_ptr for tracking.
Yes, I use this workaround where possible. I just wanted to be sure I didn't miss some straightforward solution. Thank you!
participants (2)
-
Frank Mori Hess
-
Igor R