Re: Add pselect, ppoll system calls.

From: Linus Torvalds
Date: Sun Jun 12 2005 - 22:26:28 EST




On Sun, 12 Jun 2005, jnf wrote:

> Hi. I realize this is off subject to the mailing list, however its not
> really off subject to the thread. What is the suggested method for
> dealing with this? i.e. catching sigint which sets a global variable and
> then having select() inside the loop, i.e.
>
> while (boolean < 1 ) {
> [...]
> select(...);

Nope, that will have a race in between testing "boolean" and the select.

The simplest way is to do

if (sigsetjmp(..)) {
... handle signal ...
}
for (;;) {
select(..)
}

but a lot of people find the control flow very confusing, and I can't much
blame them.

One pretty simple alternative is to just make the timeout be a global, and
have the signal handler clear it, guaranteeing that if we're just about to
hit the select(), we'll exit immediately.

A third alternative that some people prefer (although I personally find it
to be the most complex of the bunch and it's also the least efficient, but
it works in threaded environments) is to have the signal handler write a
byte to a pipe, and have the select() mask contain that pipe as one of the
inputs so that the main loop sees the signal even as a pipe readability
test.

Anyway, that's three different approaches, all of which are portable and
thus preferable to pselect() which is not.

Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/