Using d-bus from multiple threads?

Ivan Barr itb.wrk at gmail.com
Mon Aug 23 12:01:32 PDT 2010


Thanks for the reply Rémi.

I am calling the dbus_g_thread_init_default(); from the main thread before
the event loop thread is started.

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...

Ivan

2010/8/23 Rémi Denis-Courmont <remi at remlab.net>

> Le lundi 23 août 2010 20:34:37 Ivan Barr, vous avez écrit :
> > Thanks Ville,
> >
> > Is this generally received wisdom or from painful personal experience?
>
> There are ample documentation on why this really does not work in the past
> few
> months on this same mailing list. libdbus was not designed with this in
> mind.
>
> > Are the d-bus libraries designed to be thread safe or is it that it just
> > doesn't work very well?
>
> Yes and no. libdbus only claims to be thread-safe if you call the thread
> initialization function before anything in your process space uses libdbus.
> Thread initialization is not thread-safe (so you can't do it from a library
> that cannot reach main()).
>
> Also libdbus calls a bunch of non-thread-safe functions internally,
> including
> unsetenv() and Xlib.
>
> --
> Rémi Denis-Courmont
> http://www.remlab.net/
> http://fi.linkedin.com/in/remidenis
> _______________________________________________
> dbus mailing list
> dbus at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dbus
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/dbus/attachments/20100823/cf8f7be5/attachment.htm>


More information about the dbus mailing list