call I use mq_send or msgsnd from inside a signal handler

265 Views Asked by At

Is it safe to call msgsnd() or mq_send() inside a signal handler. The code would look like below.

There are two pthreads which send and receive data over a message queue in blocking mode. A signal is handled in the Thread2 context.

My doubt is whether we will lose data, when we are blocking in Bookmark1 line, when a signal_handler is executed in between as a result of, a signal handler executed from for eg a timer timeout.

Thread1
{
   while(1)
   {
        ...
        mq_send(data1)
        ...
   }
}

Thread2
{
    while(1)
    {
        ...
        mq_receive(data) // Bookmark1
        process(data) // We may start timer in this process path
        ...
    }

}
timer_timeout_signal_handler() //called from a timeout of a timer in Thread2 context.
{
    mq_send(data2)
}
0

There are 0 best solutions below