lkml.org 
[lkml]   [2001]   [Jan]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: PROBLEM: select() on TCP socket sleeps for 1 tick even if data available
Date

> If select() is waiting for data to become available on a
> TCP socket FD, and
> data becomes available, it doesn't return until the next clock tick.

If your application has scheduling requirements, you need to communicate
them to the scheduler.

> #include <sys/time.h>
> #include <sys/types.h>
> #include <unistd.h>
>
> /* this program should take 1 second to complete, but takes 10 */
> /* yes i know, it doesn't do any I/O, but the behavior is the
> same as if it did */
> main()
> {
> for (int i = 0; i < 1000; i++) {
> struct timeval to;
> to.tv_sec = 0;
> to.tv_usec = 1000;
> select(0, 0, 0, 0, &to);
> }
> return 0;
> }

This program doesn't demonstrate anything except that Linux's sleep time is
granular. This shouldn't be news to anyone. If you don't force a reschedule,
everything works the way it's supposed to:

main()
{
int i, j, pipes[2];
struct timeval tv;
fd_set rd;
pipe(pipes);
write(pipes[1], "foo", 4);
for(i=0; i<1000; i++)
{
FD_ZERO(&rd);
FD_SET(pipes[0], &rd);
tv.tv_sec=0;
tv.tv_usec=1000;
j=select(10, &rd, NULL, NULL, &tv);
if(j!=1) printf("oops\n");
}
}

DS

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

\
 
 \ /
  Last update: 2005-03-22 12:57    [W:0.060 / U:9.704 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site