From owner-freebsd-hackers@FreeBSD.ORG Thu Nov 3 05:18:25 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 92916106564A for ; Thu, 3 Nov 2011 05:18:25 +0000 (UTC) (envelope-from Deepak.Gupta2@citrix.com) Received: from SMTP.CITRIX.COM.AU (smtp.citrix.com.au [203.166.19.134]) by mx1.freebsd.org (Postfix) with ESMTP id A5FDE8FC08 for ; Thu, 3 Nov 2011 05:18:24 +0000 (UTC) X-IronPort-AV: E=Sophos;i="4.69,447,1315180800"; d="scan'208,217";a="9190347" Received: from banpmailmx02.citrite.net ([10.103.128.74]) by SYDPIPO01.CITRIX.COM.AU with ESMTP/TLS/RC4-MD5; 03 Nov 2011 05:08:20 +0000 Received: from BANPMAILBOX01.citrite.net ([10.103.128.72]) by BANPMAILMX02.citrite.net ([10.103.128.74]) with mapi; Thu, 3 Nov 2011 10:37:58 +0530 From: Deepak Gupta To: "freebsd-hackers@freebsd.org" Date: Thu, 3 Nov 2011 10:37:57 +0530 Thread-Topic: sleep/select call in a thread doesn't return if system date is changed Thread-Index: AcyZ5HCtkcZS3JTKTx+2hzFqSZFn1AAAg3zQ Message-ID: <64FB1554ABC9B44FAA773FBD6CB889C2E1CB205ADA@BANPMAILBOX01.citrite.net> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 03 Nov 2011 11:11:54 +0000 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: RE: sleep/select call in a thread doesn't return if system date is changed X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Nov 2011 05:18:25 -0000 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 a= md64" Following is the source code I'm testing: #include #include #include 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