blocking calls with keyboard and mqueues

This appears to be a common problem with a ncurses getch and mqueue
mq_receive. The attached program demonstrates the getch blocking
waiting for a key strike. The program is designed to not wait and will
not wait but at some time (after several keys are pressed sometime a few
hundred) the getch will block. If I use an alarm(1) calls then the
getch unblocks.

The attached ncurses code works fine compiled on other UNIX systems and
never blocks on them. (So I believe the ncurses portion is clean.)

I have seen this happen with a mq_receive function. In that case if I
set the MQ_NONBLOCK attribute mq_flags with mq_setattr each time before
the call the call stops blocking.

Maybe these two problems are related. I’m afraid I am masking an
underlying problem by using the alarm() and mq_setattr calls.

Thanks.

Ken Recchia <rectech@nctimes.net> wrote:

Maybe these two problems are related. I’m afraid I am masking an
underlying problem by using the alarm() and mq_setattr calls.

yes (alarm will interrupt the read).


Thomas E. Dickey <dickey@herndon4.his.com>
http://dickey.his.com
ftp://dickey.his.com