Re: Wait for "signal" from another application and/or thread

From: Kasper Dupont (remove.invalid_at_nospam.lir.dk.invalid)
Date: 09/13/04


Date: Mon, 13 Sep 2004 12:56:42 +0200

William Ahern wrote:
>
> zoom wrote:
> > Assume that we have two applications running on the same PC each with two
> > threads.
>
> > Application-1, Thread-1 :
> > . . .
> > while(!Terminated && !MYSIGNAL) {
> > //?? How to implement following line ??
>
> sigsuspend(2)

True, sigsuspend can be used. But you'd better be
carefull. What exactly does the condition mean? What
if the signal arrives before you call sigsuspend?

The major advantage of using sigsuspend over using
pause is, that with sigsuspend you can solve some
race conditions. But you can only avoid race
conditions if you use sigsuspend right, and that
means the signal must have been blocked and become
unblocked by sigsuspend.

So either you must block the signal so early, that
you are sure it cannot arrive before being blocked,
or you must verify if it did already arrive.

So it could look a bit like this:
block the signal;
if (I did not already receive the signal)
   sigsuspend(...);

If you understand your problem correct, and use
sigsuspend in a clever way, it wouldn't surprise me,
if you can end up with a simpler solution.

-- 
Kasper Dupont -- der bruger for meget tid paa usenet.
#define _(_)_"rdk"/* This is my real email address */
char _[]=_("kaspe")_("brics");_[7]='@';_[13]='.';puts(_);