threads, signals, and queues

Hello, I have been searching around for some information about a problem I have been having but haven't been able to find anything or I can't figure out how to apply what I have seen. Here is the scenario:

1)The main process creates a thread, sends a message to the thread using a message queue, then waits for a response (mq_receive).
2)The thread receives the message, starts a timer, and then sends a message back to the main process when the timer has expired (when it receives the SIGALRM signal).

The problem that is occurring is that as the main process is blocking in mq_receive, it is interrupted by the SIGALRM signal and fails receiving the message.

So my question is, is there any way to have the SIGALRM signal only go to the thread? Or for the main process to ignore the SIGALRM signal?

Any help would be appreciated. Thanks.
If you are using pthreads, each pthread has a signal mask (ie, a set of signals that it blocks). In order to direct a signal to a particular thread, you have to make all other threads (including the main program) block that signal.

Look up pthread_sigmask.

Thank you for your reply.

I did look into the pthread_sigmask but can't seem to figure out how to use it. I used this code in the main process:

static sigset_t signal_mask;
sigemptyset (&signal_mask);
sigaddset (&signal_mask, SIGALRM);
pthread_sigmask (SIG_BLOCK, &signal_mask, NULL);

And this in the thread:

static sigset_t signal_mask;
sigemptyset (&signal_mask);
sigaddset (&signal_mask, SIGALRM);
pthread_sigmask (SIG_UNBLOCK, &signal_mask, NULL);

But mq_receive is still interrupted. It seems unblocking in the thread also unblocks the main process (?).
Topic archived. No new replies allowed.