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
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Sep 20 15:00:45 GMT 2006
>Originator:     Mike Tisdell
>Release:        5.5.x
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

sleep() in a pthreaded function will return immediately if the program receives a signal.
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                                     ***


void    *pthread1()


void    sighup()

printf("Received SIGHUP\n");

void    quit()

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

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

signal(SIGHUP, &sighup);
signal(SIGQUIT, &quit);
signal(SIGKILL, &quit);
signal(SIGTERM, &quit);
rc = pthread_create(&thread1, NULL, pthread1, NULL);

return 0;



More information about the freebsd-bugs mailing list