Is destoring dbus object thread safe? #330
-
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):
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? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hello, no, it's not correct. The So in your case, the thread destructing the object would wait for at most 300 seconds until the event loop thread serving the object finishes serving the call. |
Beta Was this translation helpful? Give feedback.
Hello, no, it's not correct. The
Object
instance will not be destroyed as long as there are calls being served by that object. This is guaranteed by internal thread safety design of sdbus-c++. Thread safety chapter discusses this to some detail. It says it's completely safe to destroyObject
andProxy
instances at any time. This of course counts with the fact that there may be operations pending on those instances at that very same time -- these operations are finished first and then the object is destroyed.So in your case, the thread destructing the object would wait for at most 300 seconds until the event loop thread serving the object finishes serving the call.