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 cha= nged I have already checked these two very old messages from 2005 archive http://lists.freebsd.org/pipermail/freebsd-hackers/2005-Feb= ruary/010498.html http://lists.freebsd.org/pipermail/freebsd-hackers/2005-February/010482.htm= l but I'm surprised to see the same behavior still after 6 years in 6.3 relea= se. 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> a= md64" 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 =3D 4; tv.tv_usec =3D 0; int rc; while(1) { tv.tv_sec =3D 5; tv.tv_usec =3D 0; printf("sleeping for 5 secs\n"); rc =3D select(0, NULL, NULL, NULL, &tv); printf("Woke up after 5 sec\n"); } } int main(void) { pthread_t thread; int rc; rc =3D pthread_create(&thread, NULL, task, (void *) NULL); rc =3D 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, ev= en if few hours back, the loop sticks at "sleeping for 5 secs" forever unle= ss 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>