[pulseaudio-tickets] [Bug 62529] New: pa_threaded_mainloop_stop() blocks on pa_mutex_lock(m->mutex)

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Tue Mar 19 08:23:22 PDT 2013


https://bugs.freedesktop.org/show_bug.cgi?id=62529

          Priority: medium
            Bug ID: 62529
                CC: lennart at poettering.net
          Assignee: pulseaudio-bugs at lists.freedesktop.org
           Summary: pa_threaded_mainloop_stop() blocks on
                    pa_mutex_lock(m->mutex)
        QA Contact: pulseaudio-bugs at lists.freedesktop.org
          Severity: major
    Classification: Unclassified
                OS: Linux (All)
          Reporter: changyp6 at gmail.com
          Hardware: ARM
            Status: NEW
           Version: unspecified
         Component: clients
           Product: PulseAudio

I recently switched my pulseaudio code to pulseaudio-3.0 and used
pa_threaded_mainloop to use pulseaudio library in multi-threaded application.
I find in some cases, pa_threaded_mainloop_stop() will just block on
pa_mutex_lock(m->mutex) and never quit.

I have read the source code of pa_threaded_mainloop_stop()
pa_threaded_mainloop_run(), it seems that there is one possibility that makes
this happen.
In pa_threaded_mainloop_run(), a thread is created and pa_mainloop_run is
called and protected by pa_mutex_lock(m->mutex) and pa_mutex_unlock(m->mutex)
in the thread;

in pa_threaded_mainloop_stop(), pa_mainloop_quit is also protected by
pa_mutex_lock(m->mutex) and pa_mutex_unlock(m->mutex);

So, here is the problem, in pa_threaded_mainloop_stop(), m->mutex must be
aquired before pa_mainloop_quit() can be called, and in
pa_threaded_mainloop_run(), when pa_mainloop_run() exits, m->mutex can be
unlocked. If pa_mainloop_run() is blocked, the only way to make
pa_mainloop_run() exit is to call pa_mainloop_quit(), but pa_mainloop_quit()
can only be called after pa_mainloop_run() is quit.

This is the deadlock.

I noticed that the mutex is created with flag RECURSIVE, which only makes this
mutex can be locked recursively in the same thread. In my case,
pa_threaded_mainloop_stop() is called from another thread, so the mutex still
can block pa_threaded_mainloop_stop().

This is easy to reproduce, use pa_threaded_mainloop() to write a recording
program, and start/stop repeatedly, sometimes pa_threaded_mainloop_stop() is
deadlocked.

-- 
You are receiving this mail because:
You are the QA Contact for the bug.
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/pulseaudio-bugs/attachments/20130319/f53217b3/attachment.html>


More information about the pulseaudio-bugs mailing list