Writing to the pipe may block if the pipe is full. Holding the mutex while writing prevents listeners from
aquiring the mutex and unblocking the write. This leads to a deadlock situation.
The pipe used for signalling in the event queue was not properly
cleared when popping events, causing the select() in the main
loop to return immediately after the first event was queued,
instead of blocking for the next event.