Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 24 Feb 2005 14:27:42 +0800
From:      "River" <river_robert@yahoo.com.cn>
To:        "freebsd-hackers" <freebsd-hackers@freebsd.org>
Subject:   "sleep" "select" system call not work correctly when linking with multithread libray--FreeBSD 4.5
Message-ID:  <20050224062755.6A3A143D72@mx1.FreeBSD.org>

next in thread | raw e-mail | index | archive | help
 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;
}







Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050224062755.6A3A143D72>