<html>
    <head>
      <base href="https://bugs.freedesktop.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - mainloop wakeup is race-y and can eat 100% cpu"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=69711">69711</a>
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>lennart@poettering.net
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>pulseaudio-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>mainloop wakeup is race-y and can eat 100% cpu
          </td>
        </tr>

        <tr>
          <th>QA Contact</th>
          <td>pulseaudio-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>pierre-bugzilla@ossman.eu
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>core
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>PulseAudio
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=86366" name="attach_86366" title="0005-mainloop-avoid-race-y-double-wakeup-status.patch">attachment 86366</a> <a href="attachment.cgi?id=86366&action=edit" title="0005-mainloop-avoid-race-y-double-wakeup-status.patch">[details]</a></span>
0005-mainloop-avoid-race-y-double-wakeup-status.patch

There's been a lot of fiddling with the mainloop's wakeup code since I wrote
it. Unfortunately the current implementation is race-y and can send pa_poll()
into a loop where it returns right away and the process starts eating 100% CPU.

What happens is:

 1. pa_mainloop_wakeup() is called.

 2. A wakeup byte is written on the pipe.

 3. The atomic status variable is updated.

 4. clear_wakeup() is called.

 5. The atomic status variable is checked, and reset.

 6. The pipe is read, but data has yet to propagate from the write end to the
read end so we get nothing.

 7. poll() is called, but returns quickly as there is now a byte sitting in the
pipe.

 8. clear_wakeup() is called, but won't read anything since the atomic status
claims the pipe is empty.

 9. goto 7.

The attached patch simply removes the extra variable. The pipe has atomic
properties so it is quite sufficient by itself.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the QA Contact for the bug.</li>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>