Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Sep 2006 14:55:12 GMT
From:      Mike Tisdell <mike@netronix.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   misc/103430: sleep() in a pthread returns prematurely when a signal is recv.
Message-ID:  <200609201455.k8KEtCRl017847@www.freebsd.org>
Resent-Message-ID: <200609201500.k8KF0jIa049696@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         103430
>Category:       misc
>Synopsis:       sleep() in a pthread returns prematurely when a signal is recv.
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Sep 20 15:00:45 GMT 2006
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200609201455.k8KEtCRl017847>