I had installed a handler for SIGINT via sigaction. There's
a call to mq_send from inside that handler. The message queue
(being mq_send{t} to) was opened earlier (during initialization
of the process) _without_ specifying the O_NONBLOCK flag.
I checked Solaris2.6 man pages and it said that mq_send is
MT-safe and so I am assuming it is safe to call it from a
signal handler. Is this a safe thing to do?
The process was sent a SIGINT. I saw that it was blocked in
the handler (I am guessing because the O_NONBLOCK was _not_ set
and the message queue was full). Since SIGINT is blocked while
the handler is still executing; I could not possibly interrupt
the mq_send call using another SIGINT (am I correct?).
Curiously, I found, by attaching a debugger at this point, that
the stack trace showed "sem_wait" and "_lwp_sema_wait" (I am NOT
using POSIX threads or Sun LWPs anywhere in my application --
they all are straight forward Unix processes), in that
order, afther the call to mq_send.
Is mq_send implemented this way (to make use of semaphores)?
As the process was blocked on mq_send and further SIGINTs are
blocked, further sending SIGINT to the process never took it
out of the blocking stage of mq_send. When I sent any other signal
(for which I do not have a handler installed), the mq_send was
correctly interrupted and the call (mq_send) returned.
My questions are:
1. Does my reasoning above seem to correctly explain what
I observed in my process?
2. Is it safe to use _any_ MT-safe calls in a signal handler
(like this mq_send)?
3. Is POSIX message queue on Solaris 2.6+ implemented using
using POSIX semaphores?
Thanks a lot for your time.
Regards
Soumya
--
Soumyabrata Bhattacharya, Motorola Inc. Email : bhtt...@cig.mot.com
1501 W. Shure Drive, IL27-3227 Phone : +1-847-632-7830
Arlington Heights, IL 60004, USA Fax : +1-847-632-2867
bhtt...@buck.cig.mot.com (Soumyabrata Bhattacharya) writes:
>I checked Solaris2.6 man pages and it said that mq_send is
>MT-safe and so I am assuming it is safe to call it from a
>signal handler. Is this a safe thing to do?
No, MT-Safe does not equal safe to be called from a signal handler.
(MT-Safe functions are not necessarily reentrant; e.g., malloc
is MT-Safe but it cannot be called from a signal handler)
>Curiously, I found, by attaching a debugger at this point, that
>the stack trace showed "sem_wait" and "_lwp_sema_wait" (I am NOT
>using POSIX threads or Sun LWPs anywhere in my application --
>they all are straight forward Unix processes), in that
>order, afther the call to mq_send.
>Is mq_send implemented this way (to make use of semaphores)?
Yes.
>My questions are:
>1. Does my reasoning above seem to correctly explain what
> I observed in my process?
If mq_send gets interrupted holding the semaphore, a second call
in the signal handler will deadlock.
>2. Is it safe to use _any_ MT-safe calls in a signal handler
> (like this mq_send)?
No, only Async-Signal-Safe calls can be used (this includes most
system calls but not many library calls)
>3. Is POSIX message queue on Solaris 2.6+ implemented using
> using POSIX semaphores?
Yes, to synchronize access to the queues.
Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.