Using d-bus from multiple threads?

Burton Samograd burton at userful.com
Mon Aug 23 13:44:37 PDT 2010


Ivan Barr <itb.wrk at gmail.com> writes:

> I guess I'm hearing a mixed message. On the one hand it is claimed to
> be thread-safe under certain conditions (even though it makes use of
> non thread safe functions?). On the other hand it appears to be
> strongly not recommended to try to do this.
>
> I guess the safest thing will be to move all the d-bus code to run in
> a single thread. Does it matter if this is not the main thread? Sadly
> this will be considerable re-factoring!!
>
> Perhaps some warning should be put on the d-bus webpage to warn people
> from trying to use the library with threads? It seems from what you
> say it is not just me who has fallen into this trap...

I've managed to get dbus to work well with a threaded application (using
pthreads) but I did run into a lot of trouble when cancelling a thread
that was in the middle of a dbus call.  It seems that some locks can be
held and threads can still be cancelled while holding the lock, causing
the whole system to lock up.  I got around it with a nasty do_not_cancel
variable for the controlling thread, but it took a good day to figure
out what was going wrong.

The rest of the program seems to work fine and I haven't had any other
serious problems with recieving in one thread and making calls in
multiple others, but you might run into some more annoying problems than
I did.

Not sure if I would reccomend dbus threaded programming to the faint of
heart, but it did work for me...

--
Burton Samograd



More information about the dbus mailing list