From nobody@FreeBSD.org  Wed Sep 20 14:56:23 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 5184216A4A0
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 20 Sep 2006 14:56:23 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 0D34243DD5
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 20 Sep 2006 14:55:12 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k8KEtCbd017848
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 20 Sep 2006 14:55:12 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k8KEtCRl017847;
	Wed, 20 Sep 2006 14:55:12 GMT
	(envelope-from nobody)
Message-Id: <200609201455.k8KEtCRl017847@www.freebsd.org>
Date: Wed, 20 Sep 2006 14:55:12 GMT
From: Mike Tisdell <mike@netronix.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: sleep() in a pthread returns prematurely when a signal is recv.
X-Send-Pr-Version: www-2.3

>Number:         103430
>Category:       kern
>Synopsis:       sleep() in a pthread returns prematurely when a signal is recv.
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Sep 20 15:00:45 GMT 2006
>Closed-Date:    Tue Nov 28 02:55:14 GMT 2006
>Last-Modified:  Tue Nov 28 02:55:14 GMT 2006
>Originator:     Mike Tisdell
>Release:        5.5.x
>Organization:
Netronix
>Environment:
FreeBSD shuttle.netronix.com 5.5-PRERELEASE FreeBSD 5.5-PRERELEASE #5: Wed May 17 05:19:04 PDT 2006     root@shuttle.netronix.com:/usr/src/sys/i386/compile/SHUTTLE  i386

FreeBSD ns4.keypointcu.com 5.5-STABLE FreeBSD 5.5-STABLE #5: Mon Aug 21 15:04:27 PDT 2006     mike@ns4.keypointcu.com:/usr/src/sys/i386/compile/NS4  i386

>Description:
sleep() in a pthreaded function will return immediately if the program receives a signal.
>How-To-Repeat:
Run the following program and then SIGHUP the process. Each SIGHUP will produce the output of both sighup() and pthread1(), but not main() i.e. the sleep timer in the main thread is working properly.



/*********************************************************************************************************
***                                         pthread.c                                                  ***
***                                Pthread sleep bug demonstration                                     ***
**********************************************************************************************************/


#include<stdio.h>
#include<pthread.h>
#include<stdlib.h>

void    *pthread1()
{

while(1)
        {
        printf("pthread1\n");
        sleep(3600);
        }
}

void    sighup()
{

printf("Received SIGHUP\n");
}


void    quit()
{

printf("Received signal, quiting!\n");
exit(0);
}



int main()
{
int             rc;
pthread_t       thread1;
pthread_attr_t  thread1_attr;

signal(SIGHUP, &sighup);
signal(SIGQUIT, &quit);
signal(SIGKILL, &quit);
signal(SIGTERM, &quit);
pthread_attr_init(&thread1_attr);
rc = pthread_create(&thread1, NULL, pthread1, NULL);
while(1)
        {
        printf("main\n");
        sleep(3600);
        }

return 0;
}


>Fix:

>Release-Note:
>Audit-Trail:

From: David Xu <davidxu@freebsd.org>
To: bug-followup@FreeBSD.org,  mike@netronix.com
Cc:  
Subject: Re: kern/103430: sleep() in a pthread returns prematurely when a
 signal is recv.
Date: Mon, 27 Nov 2006 10:54:10 +0800

 sleep() can and should be interrupted by signal, otherwise
 this is a bug, the reason main thread's sleep() is not interrupted
 is dependent on the order how kernel or thread library select
 a thread which does not mask the signals.
 
 David Xu
 
State-Changed-From-To: open->closed 
State-Changed-By: davidxu 
State-Changed-When: Tue Nov 28 02:54:44 UTC 2006 
State-Changed-Why:  
Not a bug. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=103430 
>Unformatted:
