using KDBusConnectionPool in libraries
Aaron J. Seigo
aseigo at kde.org
Thu Feb 20 19:03:20 UTC 2014
Hi..
I ran into an interesting situation the other day with libkactivities: it uses
KDBusConnectionPool to create connections in a thread-safe manner.
KDBusConnectionPool creates a connection in whatever thread it happens to be
executed from. In libkactivities this creates a problem as a singleton that is
internal to the library uses KDBusConnectionPool .. so whatever thread it
happens to be called from first: that’s the thread it gets its QDBusConnection
object put into.
Of course, if that thread has no event loop and/or exits, then things stop
working as expected. In the case of libkactivities, things just stop working,
period.
Either a better solution needs to be found for KDBusConnectionPool or a
warning should be placed prominently in the apidox about this “gotcha” and
perhaps it should be completely avoided in other frameworks where it is
impossible to know the threading model of the application that will be using
it. Or, I suppose, we could invent a policy that applications should do all
dbus related activities in a specific thread .. though that can be difficult to
know as dbus calls are often hidden within libraries.
.. or, does anyone have a pointer to what exactly in QDBusConnection is not
thread safe?
--
Aaron J. Seigo
More information about the Kde-frameworks-devel
mailing list