[avahi] Avahi-Client and thread safety

Lennart Poettering lennart at poettering.de
Sun Jan 15 06:12:32 PST 2006


Hi!

When adding zeroconf support to applications that do not have a proper
event loop (like the gtk/glib main loop) the best solution usually is
to run the event loop for avahi in its own thread.

Many of the avahi enabling patches for third-party software currently
floating around try to do this (notably the the mt-daapd or the
wzdftpd patches), but don't do it properly, because they don't do
provide thread safety for avahi's client library.

A big fat warning:

       *** AVAHI-CLIENT IS NOT THREAD-SAFE! ***

At least not out-of-the-box. It doesn't require a lot of code to make
it thread safe in some way, but that code is not straighforward. Due
to this the next Avahi release will contain a new type of event loop
implementation, the "AvahiThreadedPoll" object, which does a lot of
work for you, however not everything. 

AvahiThreadedPoll is pretty self-contained, so it is easy to copy it
into your sources for compatibility with current Avahi versions.

A rough introduction how to use AvahiThreadedPoll is available in the
wiki:

        http://avahi.org/wiki/RunningAvahiClientAsThread

If you created a patch for some software which runs the avahi-client
stuff in its own thread but did not provide locking facilities, please
rework your patch to use this new AvahiThreadedPoll object!

Lennart

-- 
Lennart Poettering; lennart [at] poettering [dot] de
ICQ# 11060553; GPG 0x1A015CC4; http://0pointer.de/lennart/


More information about the avahi mailing list