For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > May 2004 > Deadlock and signals









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Deadlock and signals
B

2004-05-12, 9:08 pm

Hi everybody, I am developing a small application and I encoured in an
error. Basically, my application must use signals and I must let two
processes that run concurrently to syncronize each other.


Here is the problem: Let's say we have process A and process B.

What they do is:

process A:
kill (pid_of_B, SIGUSR1 );
sigsuspend(&mymask);


process B:
siguspend(&mymask2);
kill(pid_of_A, SIGUSR1);

Ok, the problem is that this what happens: B goes into sigsuspend. A sends
the signals to B. B gets out of sigsuspend and sends the second signal
_BEFORE_ A goes into sigsuspend. A loses the signals and it remains forever
inside the sigsuspend.
I am looking for an efficient solution for this. I have a solution but it is
not good. Here is is.


Process A:

int unlock=0;
static void sig_handler(int signo)
{
unlock=1;
}
void main()
{
/* A lot of code here */
kill (pid_of_B, SIGUSR1 );
while(!unlock);
unlock=0;
}

process B:
siguspend(&mymask2);
kill(pid_of_A, SIGUSR1);

This version works fine, because the signal handler is always called. It
never blocks (I tried it), but I don't really like this solution... is there
any better I can do?
Really thanks


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com