"sleep" "select" system call not work correctly when linking with multithread libray--FreeBSD 4.5

River river_robert at yahoo.com.cn
Thu Feb 24 06:27:55 GMT 2005


 Does anyone know why "sleep" "select" can not work correctly in FreeBSD 4.5 when the system time is set backward for a long time,i.e several hours. The behavior is: sleep or select will be blocked for a long time much longer than expected.

Through testing, we found that these two system calls both are OK if linking with the program with standard system libray, but will be blocked when linking with "-pthread" option (I suppose this option will let program link with multithread library) if system time is set backward. Seems like that the implementation of "select" "sleep" in multithread library is reated to system date. It is really wired.
 
This is select testing program-- When time is set backward,the program linked with "-pthread" option did not continue printing anything. But using the program linked with standard library, printing did not affected by system time backward and all is OK.

int main(int argc, char *argv[])
{
    fd_set  readset;
    int result =0;
    struct timeval interval;
    interval.tv_sec = 10;
    interval.tv_usec = 0;

    for(;;)
    {
        result = select(FD_SETSIZE, NULL, NULL,NULL, &interval);
        switch(result)
        {
            case -1:
                printf(" case -1\n");
                continue;
            case 0:
                printf("case 0, after select;\n");
                continue;
            case 1:
                printf("read sth\n");
                continue;
        }
    }
    return 0;
}

This is sleep testing program. Just the same result as select.

int main(int argc, char *argv[])
{

    for(;;)
    {
        printf("case 0, before sleep\n");
        sleep(5);
        printf("case 1, after sleep\n");
    }
    return 0;
}







More information about the freebsd-hackers mailing list