Tracking DBusWatches

Havoc Pennington hp at redhat.com
Wed Feb 7 10:46:51 PST 2007


tsuraan wrote:
> 
> So if I want to drop dbus into an existing application, I could just
> make a thread dedicated to calling dbus_connection_read_write_dispatch
> and register all my desired functions without really having to worry
> about anything else?  Is dbus thread-safe enough for that to work?

This should work, but you have to be prepared for the dispatch to happen 
in this special dbus thread, and not in your main app thread. i.e. your 
filter functions and so forth will be called from whatever thread is 
doing the dispatch() on the connection.

If you want to dispatch() in the main thread you can just read_write() 
in the separate thread, then get_dispatch_status() and if needed tell 
your main thread to do the dispatch.

libdbus is fairly thread-safe but does have some quirks that need 
fixing, for example you can have issues if you 
dbus_connection_send()/dbus_connection_flush() in the main thread and do 
a blocking read_write() in another thread. (See a recent discussion on 
this list.) This is a bug in libdbus but perhaps hard to fix.

If you use dbus *exclusively* in the separate thread you should 
encounter no problems that I can think of. Also if you do all 
read_write() and send()/flush() in the separate thread and dispatch() in 
the main thread I would not expect any problems.

Threads are always complicated and tend to find new bugs, though.

Havoc


More information about the dbus mailing list