It is currently Tue, 14 Jul 2020 01:12:46 GMT

Author Message
 What is async-signal safe function

 Ravi> Hi, One is not allowed to use async-signal unsafe function in
 Ravi> signal handlers. What exactly is a async-signal unsafe
 Ravi> function.?

A function is async-signal-safe if you can interrupt it with a signal,
and successfully call it from within the signal handler without it
behaving incorrectly as a result.

The usual reasons why a function could be *unsafe* with respect to
signals are:

  - the function potentially calls other functions which are not safe
    (this is why the stdio library, fopen()/fclose()/fgetc() etc. are
    unsafe, because virtually all the routines in it can call malloc()
    or free())

  - the function modifies static or global data structures (this is
    why malloc() and free() are unsafe)

In some cases an unsafe function can be made safe by blocking signals
around the unsafe parts.

Signal safety is very closely related to the more general concept of
"reentrancy" (in fact the latter term was often used, but it is not
precisely correct).

 Ravi>    From what I understand, the function (like malloc(),
 Ravi> pthread_*() ), that if reentered because of a signal
 Ravi> (asynchronous) may cause deadlock or cause some corruption are
 Ravi> async-signal unsafe.  But then if I mask out the signals during
 Ravi> the processing in my signal handler then does it make it
 Ravi> async-signal safe .

No. You would need to mask out signals during the calls *in the main
program*, not in the signal handler.

It is specifically allowed to call unsafe functions from a signal
handler *if and only if* you can guarantee that the signal did not
itself interrupt an unsafe function.


 Mon, 20 Aug 2001 03:00:00 GMT   
   [ 2 post ] 

Similar Threads

1. Why is localtime_r() not ASYNC-SIGNAL-safe ?

2. siglongjmp not async-signal-safe?

3. poll/select not async-signal safe

4. Delivery of signals when thread not async safe

5. Solaris 8 threads: If a routine is Async-Signal-Safe is it also thread Safe?

6. do signals need to be reset when using signal() function call

7. QUICK HELP NEEDED on async I/O signals.

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software