[Jack-Devel] Non-blocking I/O in process callback

Robin Gareus robin at gareus.org
Mon Nov 30 14:27:48 CET 2015


On 11/30/2015 12:11 PM, Xavier Mendez wrote:
> Hello,
> 
> I'm wondering whether it's safe to do non-blocking reads or writes from
> inside the process callback.
> 
> From what I've seen, non-blocking I/O doesn't cause the process to go
> into blocked state, and the realtime scheduler should not switch to
> another process. But the documentation doesn't seem to allow them:
> 
>> [...] it cannot call functions that might block for a long time. This
>> includes all I/O functions (disk, TTY, network), [...]
> 
> So, is it safe to use non-blocking I/O in the process callback?
> 

On which platform?

The short answer is:

  "If you don’t know how long it will take, don't do it." [1]

All i/o involve syscalls, and then it depends what the kernel does for
the specific system call(s). Asynchronous I/O usually involves signals
at some point which makes it not safe to use. Some implementation also
involve mutexes to avoid resource conflicts. You'll have to check the
standard-lib and kernel source for the system that you target.

All moot anyway. Proper software needs to do error-handling and doing
that in a rt-callback is out of the question. So you need a non-realtime
thread anyway and if you have that you can directly do i/o there.

anyway, using a ringbuffer to decouple i/o is trivial: e.g.
https://github.com/jackaudio/example-clients/blob/master/capture_client.c


best,
robin


[1]
http://www.rossbencina.com/code/real-time-audio-programming-101-time-waits-for-nothing



More information about the Jackaudio mailing list