Matt Boothe <embeddedmatt@yahoo.com> wrote:
Thanks for the replies.
Looking at MsgReceive_r, it returns -EINTR if it is interrupted by a signal.
So it seems it would be possible to do all the work (assuming I send a pulse
from my ISR as suggested) using MsgReceive_r instead of adding another
from my ISR as suggested) using MsgReceive_r instead of adding another
thread? Any reason that won’t work?
MsgReceive and MsgReceive_r will both handle the signal case – MsgReceive
will return -1, and set errno = EINTR if you get hit by a signal.
MsgReceive_r will return -EINTR. Actually, in general, MsgReceive will
return -1 on error, and set errno, while for the same error conditions
MsgReceive_r will return -errno.
Using this as your common blocking point will work very well, assuming
you use a pulse from your ISR as suggested.
One other thing, though, you probably want to make sure you ONLY receive
signals while in the MsgReceive (or as close to that as you can), because
if you get hit by a signal anywhere else, it will be a real pain.
You will probably want to:
- mask all signals as part of your initialization
- attach a signal handler to the signals you want to handle
- in that signal handler, deliver a pulse to your main thread
- unmask just the signals you are willing to accept before your
MsgRecevie[_r] call
- mask the signals after you return from MsgReceive[_r].
(You deliver the pulse from the signal handler to deal with cases where the
signal is sent before or after you go RECEIVE blocked in yoru MsgReceive()
call.)
Also, I notice that in the IPC chapter of the System Architecture Guide
there is a summary of signals and that some of them cannot be caught or
ignored, e.g. SIGKILL. This would seem to present a problem for me. Recall
that I want to be able to exit my forever loop and shutdown my hardware
before I exit the process. I’m really not sure what to do about that.
You can’t do anything about SIGKILL. POSIX mandates that SIGKILL must be
non-maskable, non-catchable, non-handleable. It’s often called
“kill-em-dead”. (Well, you can make your system such that it will never
send a SIGKILL - write no programs that deliver, don’t include any
programs that will let a user deliver an arbitrary signal to a process.
[e.g. slay, kill, qconn]).
Maybe my POSIX.4 book (in the mail) will help me answer this kind of
question. I’m pretty hazy on the entire issue of signals. I’m guessing
that signal handling is obvious to people with a UNIX background because
they were hardly even mentioned in the “Getting Started” book by Krten.
Unfortunately for me, my background is with RTOS’s, not UNIX.
QNX’s implementation of signals is pretty well pure POSIX. And, yes,
they are generally pretty well covered by most any decent Unix or
POSIX programming guide. This is (I expect) one of the reasons that
Rob’s (very good) book doesn’t cover them. The other is, I expect,
that, compared to pulses, signals are a major pain to deal with.
[BTW, my favourite Unix programming book is Advanced Programming in the
Unix Environment by W. Richard Stevens.]
-David
David Gibbs
QNX Training Services
dagibbs@qnx.com