misc/103430: sleep() in a pthread returns prematurely when a signal is recv.

Mike Tisdell mike at netronix.com
Wed Sep 20 08:01:06 PDT 2006


>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 at 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 at 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:


More information about the freebsd-bugs mailing list