Dbus in Multi-threaded application

Abhi Arora abhiarora4 at live.com
Sun Aug 27 09:52:21 UTC 2017


Hello Community,


I have developed an application for BLE using DBUS for Linux. It is working fine but sometimes I have seen seg fault.


My application has a single event loop thread for dbus (THREAD A). I have used glib event loop. It is exactly similar to "bluetoothctl" event loop implementation: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/gdbus/mainloop.c . I using that thread for receiving signal and error dbus messages using filter callbacks (by using function "dbus_connection_add_filter"). I have set watch and timeout handlers using glib implementation (by calling dbus_connection_set_watch_functions, dbus_connection_set_timeout_functions and dbus_connection_set_dispatch_status_function). You can check the above link as i have using their code.


My main thread (THREAD B) calls dbus methods and block on pending call instance for replies. I am not sure whether there could be some race condition with current software architecture as I have seen seg fault and valgrind showed it was related to invalid memory read and write in my timeout implementation. Unfortunately, I was not able to record the valgrind output and seg fault never occured after that. I just want to be sure I am doing it correctly so I won't see seg fault if I release my software.


For example, THREAD B calls a dbus method and it has set a timeout for it. I will then block on it. The THREAD A may dispatch a timeout event if timeout has occurred. I am not completely sure but I think there could be some race condition in this case. Please help me.


Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/dbus/attachments/20170827/5b563fca/attachment.html>


More information about the dbus mailing list