A signal race condition
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > A signal race condition




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    A signal race condition  
pat saunders


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
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 ]



    Re: A signal race condition  
Loic Domaigne


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-19-04 07:34 AM

Hi Pat,

> I am wondering whether anyone can help me with fixing a signal race
> condition.

Unfortunately, I won't answer your question directly...

> Basically I have two processes, one reading from a shared queue and the
> other writing message onto the message queue.

Do you mean, you are using shared memory? Because, if you need a mechanism
for sleeping as long as no data are available, then I would maybe consider
another form of IPC (message queue / FIFO / Unix Socket Domain etc.).

The major advantages of those, is that the synchronization mechnism is
built-in. The reading process performs a blocking read on the queue, and
is put (resp. awaken) by the kernel when no data are available (resp. data
has arrived).

Otherwise, if you want to stay with this "shared queue", then consider
rather semaphores (Posix or SysV) for synchronizing. And if you really want
to synchronize your processes with signal, then maybe you should consider
Real-Time signals (AFAIK, SIGCONT isn't queued. This might be a problem).


Regards,
Loic.

--
Article posté via l'accès Usenet http://www.mes-news.com
Accès par Nnrp ou Web





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 03:42 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register