Bug#292154: NPTL: pthread_create has a race condition
Package: libc6
Version: 2.3.2.ds1-20
Severity: normal
NPTL as included in debian has a race condition with pthread_create and
pthread_exit. The program in attachment exposes the race : the main
thread exits with pthread_exit and the whole program exits whereas there
is yet another thread.
Please, consider applying the fix already present upstream
Extract of the relevant part of the upstream Changelog :
2004-11-09 Roland McGrath <roland@redhat.com>
[BZ #530]
* sysdeps/pthread/createthread.c (do_clone): Increment __nptl_nthreads
here, before calling clone.
* pthread_create.c (start_thread): Don't do it here.
Best regards,
Vincent
-- System Information:
Debian Release: 3.1
APT prefers testing
APT policy: (500, 'testing')
Architecture: i386 (i686)
Kernel: Linux 2.6.4-fkt
Locale: LANG=C, LC_CTYPE=fr_FR@euro
Versions of packages libc6 depends on:
ii libdb1-compat 2.1.3-7 The Berkeley database routines [gl
-- no debconf information
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <assert.h>
#define FOREVER for(;;)
static void* thread(void*);
int
main()
{
pthread_t tid;
int status;
status = pthread_create (&tid, NULL, thread, NULL);
assert (status==0);
status = pthread_detach (tid);
assert (status==0);
/* sleep (1); */
pthread_exit (NULL);
}
void*
thread(void* unused)
{
FOREVER {
fprintf (stderr,"a");
sleep(3);
}
}
Reply to: