02-19-04 03:33 AM
Hi,
I am wondering whether anyone can help me with fixing a signal race conditio
n.
Basically I have two processes, one reading from a shared queue and the othe
r
writing message onto the message queue.
The reading process goes to sleep (pause) if no messages are on the queue an
d
the writing process after writing a message to the queue , sends a SIGCONT
signal to the reading / sleeping process to wakeup and read message.
Here is a snipet of code from reading process :
Ev_get_event(boolean wait)
{
if event queue is empty
{
if (wait == FALSE)
{
return no_event;
}
else (sleep until SIGCONT signal recieved)
{
pause();
}
} process message on event queue;
}
The Race condition can happen between the (sleep until SIGCONT) and the paus
e().
If a SIGCONT is received , the process will still pause() and miss the messa
ge.
I have come up with a solution and wonder if it will work ???
Ev_get_event(boolean wait)
{
/* Block SIGCONT */
Sigemptyset(&zeromask);
Sigemptyset(&oldmask);
Sigemptyset(&newmask);
Sigaddset(&newmask, SIGCONT);
Sigprocmask(SIG_BLOCK, &newmask, &oldmask);
if event queue is empty
{
if (wait == FALSE)
{
/* unblock SIGCONT */
Sigprocmask(SIG_SETMASK,&oldmask,NULL);
return no_event;
}
else (sleep until SIGCONT received)
{
/* Replace Pause with Sigsuspend */
Sigsuspend(&zeromask);
/* Unblock SIGCONT */
Sigprocmask(SIG_SET_SETMASK, &oldmask, NULL);
}
} process message on event queue;
/* unblock SIGCONT */
Sigprocmask(SIG_SET_SETMASK, &oldmask, NULL);
}
Any Help appreciated
Pat
[ Post a follow-up to this message ]
|