Re: Signal-Unsafe Problem



Hi Steve,

Thanks for your reply.

"Steve Greenland" <steveg@xxxxxxxxxxxxx> wrote in message
news:444cde30$0$594$a726171b@xxxxxxxxxxxxxxxxxx
According to LaBird <wlcheung2006@xxxxxxxxx>:
I am writing a program which will accept asynchronous socket messages.
Hence I need to implement a SIGIO handler, and more importantly,
I need to disable signals for certain signal-unsafe functions (such as
malloc or printf)

Um, not sure what you mean by "signal-unsafe". Do you mean "thread
unsafe"? Or do you mean "non-reentrant", and that you can't call them
from within a signal handler? Actually, you can't do much of anything
within the signal handler itself; the usual strategy is to set or clear
a simple atomic variable and return, so that the program mainline may do
the actual work.

Actually I mean "non-reentrant". In my program, I need to receive
request from other machines, so my signal handler becomes sort of
"fat", needing to decode the message, serve the request and then
send the reply.

Disable/block the signals before you start the I/O. Or, are you worried
that you'll get another SIGIO during the SIGIO handler? You're looking
for the 'sigaction()' function, which sets up the (e.g.) SIGIO handler,
and guarantees the further SIGIOs are blocked while the handler is
running. (Actually, in modern systems, signal() is implemented in terms
of sigaction(), but older systems may not do that. Also, sigaction()
lets you block other signals during the SIGIO handler, to the point that
you may not need sigprocmask() at all,)

In fact I have made an error in my question -- I have checked that
sigprocmask() is itself reentrant according to POSIX standard. The
problem should then trim down to performance issue: I need to write
a wrapper for every non-reentrant function being called, and this
becomes sort of slow.

Best Regards,
LaBird (Benny).


.



Relevant Pages

  • Re: Signal-Unsafe Problem
    ... Hence I need to implement a SIGIO handler, and more importantly, ... I need to disable signals for certain signal-unsafe functions (such as ...
    (comp.os.linux.development.apps)
  • Signal-Unsafe Problem
    ... Hence I need to implement a SIGIO handler, and more importantly, ... I need to disable signals for certain signal-unsafe functions (such as ... which is used to disable signal interrupt. ...
    (comp.os.linux.development.apps)