Skip to content

Is destoring dbus object thread safe? #329

Description

@Snarpix

If I have understood correctly destroying object is currently not thread safe.

Let's look at example(modified, from https://github.com/Kistler-Group/sdbus-cpp/blob/master/docs/using-sdbus-c++.md):

class Concatenator : public sdbus::AdaptorInterfaces<org::sdbuscpp::Concatenator_adaptor /*, more adaptor classes if there are more interfaces*/>
{
public:
    Concatenator(sdbus::IConnection& connection, std::string objectPath)
        : AdaptorInterfaces(connection, std::move(objectPath))
    {
        registerAdaptor();
    }

    ~Concatenator()
    {
        unregisterAdaptor();
    }
   
   const std::string member_ = "12313123213";

protected:
    std::string concatenate(const std::vector<int32_t>& numbers, const std::string& separator) override
    {
            std::this_thread::sleep_for(300s);
           return member_;
    }
};

In this case calling unregisterAdaptor will stop new calls to concatenate method from happening, but if some call is already waiting on std::this_thread::sleep_for(300s); then when wait finishes it will access member_, which was already destroyed.

Is my reasoning correct?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions