[alsa-devel] Unblock MIDI IN in blocking read mode

Clemens Ladisch cladisch at fastmail.net
Thu Apr 12 09:12:58 CEST 2007

Florian wrote:
> for best performance, I use a blocking snd_rawmidi_read() on an ALSA
> MIDI input device, byte by byte. It works fine, except:
> 1) How do I close the device from a different thread?

You don't.  The ALSA library isn't thread-safe; you cannot close the
device as long as the read() is still executing.

> I.e. how can I unblock the blocking read() call when it's time to
> close the device and no MIDI data is currently coming in?

You cannot.  The blocking read() unblocks when there is data to read,
or when an error occurs.  The raw MIDI functions do not implement an
API for non-MIDI messages.

> Maybe I can resort to non-blocking mode and avoid the situation above.

Yes; use another file descriptor (a pipe or something like that) that
can be used to let poll() return.


More information about the Alsa-devel mailing list