Skip to content

Conversation

rmorehead
Copy link

The smart pointer C++ reference counting utilized by the DBus::Private
_pvt pointer isn't thread safe, so sharing/copying DBus:Message
instances across threads leads to crashes/DBus C library asserts as
Private pointer objects are released prematurely.

Rather than trying to make the reference counting itself thread-safe,
and slowing down single threaded usage, a share_private optional
argument is added the copy constructor. The share_private argument
defaults to true, which preserves the existing behavior of sharing the
Private* and associated reference counting.

If the share_private copy constructor argument is instead given as
false, a new instance is created with a new Private _pvt pointer and
unique reference count, which is logically "divorced" from the
original except that is refers to the same C DBus library pointer.

Note that the C DBus library handles its reference counting in
a thread safe manner.

This new object can then be utilized by another thread without
affecting the reference counting of the original.

The smart pointer C++ reference counting utilized by the DBus::Private
_pvt pointer isn't thread safe, so sharing/copying DBus:Message
instances across threads leads to crashes/DBus C library asserts as
Private pointer objects are released prematurely.

Rather than trying to make the reference counting itself thread-safe,
and slowing down single threaded usage, a share_private optional
argument is added the copy constructor. The share_private argument
defaults to true, which preserves the existing behavior of sharing the
Private* and associated reference counting.

If the share_private copy constructor argument is instead given as
false, a new instance is created with a new Private _pvt pointer and
unique reference count, which is logically "divorced" from the
original except that is refers to the same C DBus library pointer.

This new object can then be utilized by another thread without
affecting the reference counting of the original.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant