|
| 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
|
|