dbus_connection_read_write_dispatch sometimes causing 100% cpu usage

Burton Samograd burton at userful.com
Fri Sep 10 11:56:42 PDT 2010


Burton Samograd <burton at userful.com> writes:

I've now run into this problem (100% CPU usage in dbus) in another
program of mine (it turns out the first program I was talking was
failing somewhere else). I have built dbus with debugging symbols so I
can step through the code internals to see what is happening.

My program, occasionally, gets stuck in
_dbus_connection_acquire_dispatch (in dbus-connection.c).  The relevant
lines it is looping on are:

while (connection->dispatch_acquired)
    {
      _dbus_verbose ("%s waiting for dispatch to be acquirable\n",
                     _DBUS_FUNCTION_NAME);
      _dbus_condvar_wait (connection->dispatch_cond, 
                          connection->dispatch_mutex);
    }

For the first part, I am having trouble finding how this code will ever
exit the loop, since connection->dispatch_acquired is never set
anywhere.  This seems like a standard infinite loop, but maybe someone
could shed some light on how this is supposed to exit.

The relevant code for _dbus_condvar_wait is:

{
  if (cond && mutex && thread_functions.condvar_wait)
    (* thread_functions.condvar_wait) (cond, mutex);
}


but since thread_functions.condvar_wait is 0, the code is never executed
(since I don't call dbus_init_threads (or whatever that function is
called) in my code since it is single threaded)...

Here is a stack trace from where I am in the loop:

#0  _dbus_connection_acquire_dispatch (connection=0x1053c00) at dbus-connection.c:3864
#1  0x00007f96c57726bb in dbus_connection_dispatch (connection=0x1053c00) at dbus-connection.c:4303
#2  0x00007f96c5770654 in _dbus_connection_read_write_dispatch (connection=0x1053c00,
    timeout_milliseconds=100, dispatch=1) at dbus-connection.c:3431
#3  0x00007f96c5770a22 in dbus_connection_read_write_dispatch (connection=0x1053c00,
    timeout_milliseconds=100) at dbus-connection.c:3513
#4  0x0000000000406f16 in main (argc=2, argv=0x7fff65cafec8) at userful-pfkd.c:1932

Any idea on what might be happening here?  This is really a showstopper
for me and I would really like to get it fixed if I can.

Thank in advance.

--
Burton Samograd



More information about the dbus mailing list