This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Possible pthread_create issue (crash in __pthread_create_2_1 when spawning aggressively)
- From: Xavier Roche <xavier dot roche at scality dot com>
- To: libc-help at sourceware dot org
- Date: Mon, 26 Dec 2016 17:12:52 +0100
- Subject: Possible pthread_create issue (crash in __pthread_create_2_1 when spawning aggressively)
- Authentication-results: sourceware.org; auth=none
Hi folks!
With glibc 2.23 on Linux (tested platform: Ubuntu 16, 4.6.3), the
following stress program crashes inside __pthread_create_2_1. Expected
behavior would be either a successful thread creation, or an error
returned by pthread_create.
$ while /tmp/thread_stress; do :; done
Caught SEGV in pid 18158
[2]+ Stopped /tmp/thd
$ gdb -p 18158
(gdb) where
#0 0x00007f93280bd767 in kill () at ../sysdeps/unix/syscall-template.S:84
#1 0x0000000000400a1d in segv ()
#2 <signal handler called>
#3 __pthread_create_2_1 (newthread=<optimized out>, attr=<optimized
out>, start_routine=<optimized out>, arg=<optimized out>) at
pthread_create.c:713
#4 0x000000000040089e in main ()
I couldn't find any related issue on the bug tracker. Could someone
kindly confirm that this is the case with a recent glibc ?
thread_stress.c:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/types.h>
#include <signal.h>
static void * func_pthread(void *u)
{
return NULL;
}
static void segv(int sig)
{
/* Technically we aren't allowed to use printf here (not async-signal safe) */
printf("Caught SEGV in pid %d\n", getpid());
/* Wait for a debugger */
kill(getpid(), SIGSTOP);
pause();
}
void spawn_a_thread()
{
/* Catch SEGV */
signal(SIGSEGV, segv);
/* Create detached */
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_t th;
int ret;
if( (ret = pthread_create(&th, &attr, func_pthread, NULL)))
{
perror("pthread_create");
abort();
}
}
int main(void)
{
int i;
for(i = 0; i < 32768; i++) {
spawn_a_thread();
}
return EXIT_SUCCESS;
}
--
<http://go.scality.com/acton/media/18585/gartner-magic-quadrant-object-storage?utm_campaign=MQ&utm_medium=Email&utm_source=signatures>