Re: Events
Neil Brown (neilb@cse.unsw.edu.au)
Tue, 27 Jun 2000 21:42:59 +1000 (EST)
On June 27, hans-christoph.rohland@sap.com wrote:
> Alan Cox <alan@lxorguk.ukuu.org.uk> writes:
>
> > > For example we have a thread, this thread handle the file
> > > IO. When I'm wating for some data I can use the select
> > > function to check it out if there is anything for me. If I
> > > want to stop the thread during the select, I have no other
> > > way except for the signal handlers functions.
> > > It is not really handy, because the example above is too
> > > simple. In our case is much more difficulter.
> >
> > Signal handling should do the job fine.
>
> No, that's not right (and would be _really_ happy to stand
> corrected). select and signals for interruption are not
> compatible. You always have a race condition between unblocking the
> signal and actually getting into select. AFAIK POSIX defines the
> pselect call for this problem which also introduces a signal mask
> argument. Without this, signals are useless to interrupt select.
>
> Greetings
> Christoph
>
I hit just such a race in xdm with xdmcp enabled. Because of the
particular way I was using it (forcibly logging students in labs off by
signalling xdm) I was caught by this race moderately often.
What I did was make the "struct timeval" which was passed to select a
global, and had the signal handler set it to 0,0. If the signal came
in before the select, the select would exit immediately due to a
timeout.
Works well.
NeilBrown
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/