DBus Threading in a Late-loading module

Nate Nielsen nielsen-list at memberwebs.com
Sun Apr 1 19:39:44 PDT 2007


Another threading question related to DBus. I've looked through the this
list (at least my personal archive) and found plenty of advice with
regard to DBus and threads. However this situation is very specific:

I'm working on a PKCS#11 crypto module (which is a dynamically loadable
and unloadable shared object) for gnome-keyring. I'm looking to use DBus
private connections for communication with gnome-keyring-daemon. Note
that these wouldn't go through the DBus session or system bus.

PKCS#11 modules need to be thread aware and safe. So if I were to use
DBus I'd probably need to call: dbus_threads_init_default()

However, if the module was loaded/initialized late in a process's
execution, and any DBus communication elsewhere in the process was
already underway, calling dbus_threads_init_default() would probably
cause problems, no?

The problematic sequence of events might be:

 1. Application using DBus is started
 2. DBus threading not initialized
 3. Various DBusConnections opened and calls are in progress
 4. Later, gnome-keyring's PKCS#11 module loaded
 5. The module calls dbus_threads_init_default()

Another course of action would be to use one DBusConnection per thread.
This fits in well with PKCS#11's idea of sessions.

If I limit each DBusConnection to strictly one thread and lock
appropriately, will DBus be threadsafe even without calling
dbus_threads_init_default()? Again, note that these are private
connections without going through the DBus session or system bus.

I'm not looking for a 'get-out-of-jail-free' card :) Just evaluating
DBus as an IPC mechanism for this particular use.

Cheers,
Nate Nielsen



More information about the dbus mailing list