[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in select()?

From: Marcus Brinkmann
Subject: Re: Bug in select()?
Date: Fri, 5 Jan 2001 20:05:03 +0100
User-agent: Mutt/1.1.4i

On Sun, Dec 10, 2000 at 04:35:24AM -0500, Roland McGrath wrote:
> Hmm.  Please file a bug report against libc in the Debian BTS about this,
> so that we retain a record of the problem that we won't overlook later.
> Can we get a test program that doesn't require anything unusual to be
> installed or running?

There was one in the Debian BTS, I am including it below.

> I suspect that this problem might well arise in any
> case where a polling select (or poll) call is done.  So just a simple
> program that does select on stdin might show the problem (e.g. the program
> does sleep(5), then a polling select on stdin, and during the pause you
> type a line).

That's what the program does.
> I think this may well be a basic problem with how we do select.  You might
> try hacking the select code in libc (libc/hurd/hurdselect.c) so that it
> uses a minimal (1ms) timeout for the RPC replies instead of truly polling.
> That might give the minimal time required for the "immediate" RPC replies
> to come back.  Actually just tweaking your test program would have the
> exact same effect: just find the minimum timeout value that works.

It shows the bug for usec <= 999 and not for usec >= 1000. I think this
is because smaller values than 1000 become zero in _hurd_select:

  mach_msg_timeout_t to = (timeout != NULL ?
                           (timeout->tv_sec * 1000 +
                            timeout->tv_nsec / 1000000) :

(where nsec is use * 1000, so 1000*1000 / 1000000 is 0)

(The program in the bts has a fixed value, I replaced this with
atoi(argv[1]), so call the program with one argument, the number of usecs).


When the timeout value in a call to select() is small (less than about
1000 usec) select returns 0, even if the file descriptors have changed.
I'm using the Hurd version 20001204.

The following program does not work under Hurd:

#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>

int main(int argc, char **argv)
  fd_set fds;
  struct timeval tv;

  FD_SET(1, &fds);
  tv.tv_sec = 0;
  tv.tv_usec = atoi(argv[1]);

  printf ("Press Enter\n");


  if (!select(2, &fds, NULL, NULL, &tv))
    printf("You did not push ENTER\n");
    printf("You pushed ENTER\n");

  return 0;

`Rhubarb is no Egyptian god.' Debian http://www.debian.org brinkmd@debian.org
Marcus Brinkmann              GNU    http://www.gnu.org    marcus@gnu.org

reply via email to

[Prev in Thread] Current Thread [Next in Thread]