sleep/select call in a thread doesn't return if system date is
changed
Deepak Gupta
Deepak.Gupta2 at citrix.com
Thu Nov 3 05:18:25 UTC 2011
From: Deepak Gupta
Sent: Thursday, November 03, 2011 10:37 AM
To: 'freebsd-hackers at freebsd.org.'
Subject: sleep/select call in a thread doesn't return if system date is changed
I have already checked these two very old messages from 2005 archive
http://lists.freebsd.org/pipermail/freebsd-hackers/2005-February/010498.html
http://lists.freebsd.org/pipermail/freebsd-hackers/2005-February/010482.html
but I'm surprised to see the same behavior still after 6 years in 6.3 release. Has anybody else also faced this anomaly?
Following is output of "uname -a" on my system
"FreeBSD Freebsd_31.203 6.3-RELEASE FreeBSD 6.3-RELEASE #0: Wed Jan 16 01:43:02 UTC 2008 root at palmer.cse.buffalo.edu:/usr/obj/usr/src/sys/SMP<mailto:root at palmer.cse.buffalo.edu:/usr/obj/usr/src/sys/SMP> amd64"
Following is the source code I'm testing:
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
void *task(void *argument)
{
struct timeval tv;
tv.tv_sec = 4;
tv.tv_usec = 0;
int rc;
while(1)
{
tv.tv_sec = 5;
tv.tv_usec = 0;
printf("sleeping for 5 secs\n");
rc = select(0, NULL, NULL, NULL, &tv);
printf("Woke up after 5 sec\n");
}
}
int main(void)
{
pthread_t thread;
int rc;
rc = pthread_create(&thread, NULL, task, (void *) NULL);
rc = pthread_join(thread, NULL);
}
Upon execution the program keeps printing "sleeping for 5 secs" followed by "Woke up after 5 sec". As soon as I set the system date to a back date, even if few hours back, the loop sticks at "sleeping for 5 secs" forever unless I resume the system date. When I resume the system date to current date the program also resumes to normal execution!!!
I'm sure that FreeBSD will still not be living with such a big anomaly and there is something amiss in my program itself. Please help me to figure out whats wrong in this.
Thanks
Deepak
More information about the freebsd-hackers
mailing list