Discussion:
libsystemd: Should each thread open its own dbus connection (sd_bus*)?
(too old to reply)
Fabian Knapp
2018-11-16 08:02:51 UTC
Permalink
I have an executable that opens a dbus connection with sd_bus_open_system at init time and cleanup and close this connection only on exit.

This connection is used in multiple threads (in a thread safe manner) and im wondering if this is suitable since sd_bus_add_match seems to time out if the sd_bus* object is created from another thread than the call to sd_bus_add_match happens.
Lennart Poettering
2018-11-16 13:15:01 UTC
Permalink
Post by Fabian Knapp
I have an executable that opens a dbus connection with
sd_bus_open_system at init time and cleanup and close this
connection only on exit.
This connection is used in multiple threads (in a thread safe
manner) and im wondering if this is suitable since sd_bus_add_match
seems to time out if the sd_bus* object is created from another
thread than the call to sd_bus_add_match happens.
sd-bus is not thread-safe. If you want to share connections between
threads you have to add a lock around it, which you need to allocate
yourself, and take whenever you access the bus and release it right
after.

I'd generally suggest using one connection per thread though, but this
has drawbacks (no global ordering and so on), so it really matters on
your usecase. But key really is: whatever you do, if you do use the
same bus object from multiple threads you need to lock around it,
sd-bus is not thread-safe on is own.

Lennart
--
Lennart Poettering, Red Hat
Continue reading on narkive:
Loading...