Date: Thu, 3 Nov 2011 10:37:57 +0530 From: Deepak Gupta <Deepak.Gupta2@citrix.com> To: "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org> Subject: RE: sleep/select call in a thread doesn't return if system date is changed Message-ID: <64FB1554ABC9B44FAA773FBD6CB889C2E1CB205ADA@BANPMAILBOX01.citrite.net>
next in thread | raw e-mail | index | archive | help
From: Deepak Gupta
Sent: Thursday, November 03, 2011 10:37 AM
To: 'freebsd-hackers@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@palmer.cse.buffalo.edu:/usr/obj/usr/src/sys/SMP<mailto:root@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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?64FB1554ABC9B44FAA773FBD6CB889C2E1CB205ADA>
