About dbus watch functions
Simon McVittie
simon.mcvittie at collabora.co.uk
Mon Jul 11 01:55:09 PDT 2011
On Mon, 11 Jul 2011 at 15:48:38 +0800, Weng Xuetian wrote:
> I'd like to use simplest select() to write a multi-thread dbus
> program. It has multi event source (including dbus), all event will
> be processed under their own thread, and all thread might send dbus
> message out.
You'd make life much easier for yourself if you do all interaction with
D-Bus in one thread (either your main thread, as is traditional with
dbus-glib, or a dedicated D-Bus thread, as is done internally by GDBus)
and never block that thread (except in a select(), poll() or equivalent
that includes the D-Bus fd).
(You'd also make life much easier for yourself if you use a well-known
main loop implementation, like GLib's GSource/GMainContext/GMainLoop
or Qt's QCoreApplication.)
If you insist on using D-Bus from several threads, you are likely to encounter
threading-related bugs, which are often difficult to diagnose, such as:
https://bugs.freedesktop.org/show_bug.cgi?id=857
https://bugs.freedesktop.org/show_bug.cgi?id=19796
https://bugs.freedesktop.org/show_bug.cgi?id=23584
https://bugs.freedesktop.org/show_bug.cgi?id=27585
Patches to fix any of those bugs would be appreciated!
> Should I care about add_function and other callback being called
> again while the program is running?
Yes, they can be called while dispatching the DBusConnection.
> Since there is a main loop
> thread poll for dbus fd, if it is blocked, add or remove watcher
> will not be possible.
If you provide a wakeup_main function, it will be called; you could write
through a pipe-to-self to wake up your main thread?
S
More information about the dbus
mailing list