12 Apr
2007
12 Apr
'07
9:12 a.m.
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:
- 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.
HTH Clemens