On Thu, 16.04.09 17:59, Zhang, Xing Z (xing.z.zhang at intel.com) wrote: > Hi Lennart: > It seems mainloop is not thread safe. I'd like to cite time_free as > example, pls correct me if I miss something. > > cleanup_time_events() simply iterates time_events list to free dead > events and decrease time_events_please_scan. If there are three time > events in list, #1, #2, #3, and cleanup_time_events() currently at > #2 to check whether it is dead. > > Now another thread call time_free() on #1 which will increase > time_events_please_scan. Then pa_assert(m->time_events_please_scan > == 0); will fail when iteration ends in cleanup_time_events(). > > I didn't encounter this case but from code it exists in theory. Quoting the doxygen generated docs: <snip> The PulseAudio client libraries are not designed to be directly thread-safe. They are however designed to be reentrant and threads-aware. </snip> So, nothing in PA is thread safe on its own. However the whole thing is written with threads in mind. It is your job however to place the appropriate locks. If you use the pa_threaded_mainloop mainloop implementation there are a couple of functions that ease development with threads. However, it's always your job to put the appropriate pa_threaded_mainloop_lock() and pa_threaded_mainloop_unlock() each time you access one of the PA client objects. Lennart -- Lennart Poettering Red Hat, Inc. lennart [at] poettering [dot] net ICQ# 11060553 http://0pointer.net/lennart/ GnuPG 0x1A015CC4