PulseAudio  16.0
Main Loop


The built-in main loop implementation is based on the poll() system call. It supports the functions defined in the main loop abstraction and very little else.

The main loop is created using pa_mainloop_new() and destroyed using pa_mainloop_free(). To get access to the main loop abstraction, pa_mainloop_get_api() is used.


The main loop is designed around the concept of iterations. Each iteration consists of three steps that repeat during the application's entire lifetime:

  1. Prepare - Build a list of file descriptors that need to be monitored and calculate the next timeout.
  2. Poll - Execute the actual poll() system call.
  3. Dispatch - Dispatch any events that have fired.

When using the main loop, the application can either execute each iteration, one at a time, using pa_mainloop_iterate(), or let the library iterate automatically using pa_mainloop_run().


The main loop functions are designed to be thread safe, but the objects are not. What this means is that multiple main loops can be used, but only one object per thread.