Is dbus_pending_call_set_notify() thread safe?

Havoc Pennington hp at
Tue Jul 31 14:02:54 PDT 2007


Fan Wu wrote:
> I have a question for the following code:
>   dbus_connection_send_with_reply();
>   dbus_pending_call_set_notify();
> My understanding is dbus_connection_send_with_reply() will not only
> add the message to the queue but actually tries to send it. If there
> is a dispatcher running in another thread and the reply  comes back
> and is handled before dbus_pending_call_set_notify() is run, my
> callback will never be called.
> If this is a valid issue I suggest the two functions above be merged
> into one so that the callback is set when the pending call is created.

I would guess few people encounter this since set_notify() is usually 
used as an alternative to threads, rather than in conjunction with 
threads. With threads you can just send_with_reply_and_block() perhaps.

That aside, I believe what should work is to set your notify, then call 
dbus_pending_call_steal_reply(). If the reply arrived before you set the 
notify, then it will be returned from steal_reply().

That is sort of inconvenient and unintuitive, I know.

Perhaps we could add a send_with_reply_notify() that takes the notify 
func/data/free_data_func and manages the pending call object for you.

However, libdbus generally avoids convenience API and I'm not sure we 
need send_with_reply_notify() for the benefit of bindings...


More information about the dbus mailing list