This is the mail archive of the
gdb-prs@sourceware.org
mailing list for the GDB project.
Re: threads/2149: thread_db_get_info: cannot get thread info: genericerror on fork()/execvp()
- From: Alex Bligh <alex at alex dot org dot uk>
- To: nobody at sources dot redhat dot com
- Cc: gdb-prs at sources dot redhat dot com,
- Date: 13 Aug 2006 20:38:01 -0000
- Subject: Re: threads/2149: thread_db_get_info: cannot get thread info: genericerror on fork()/execvp()
- Reply-to: Alex Bligh <alex at alex dot org dot uk>
The following reply was made to PR threads/2149; it has been noted by GNATS.
From: Alex Bligh <alex@alex.org.uk>
To: Daniel Jacobowitz <drow@false.org>
Cc: "Matthew M. DeLoera" <mdeloera@exacq.com>,
gdb-gnats@sources.redhat.com
Subject: Re: threads/2149: thread_db_get_info: cannot get thread info: generic
error on fork()/execvp()
Date: Sun, 13 Aug 2006 21:36:55 +0100
The following pretty trivial program replicates the problem
100% of the time. Thanks to Matthew for the hint. I suspect
you only need 2 threads to join. Compile instructions
included.
Alex
/* pth_dmo.c - pthreads demo.
*
* SYNOPSIS
*gcc -D_REENTRANT -lpthread -o pth_dmo pth_dmo.c
*./pth_dmo
*
* DESCRIPTION
*Starts an arbitrary number of threads that do essential-
*ly nothing but print the sequence number they were started
*in. Uses pthread_join to "reap" the started threads.
*
*If nothing is done to synchronize the threads, usually
*no output will appear; otherwise, you should see
*
* Thread 1 reporting
* Thread 2 reporting
* Thread 3 reporting
*
* PTHREAD_JOIN (See man pthread_join)
*
*int pthread_join(pthread_t th, void **thread_return);
*
*pthread_join suspends the execution of the calling
*thread until the thread identified by th terminates,
*either by calling pthread_exit(3) or by being cancel-
*led. The location pointed to by the thread_return arg-
*ument contains the exit status of thread th; it can be
*NULL. The integer returned is zero if everything went
*alright, which it usually does in this simple program.
*
* ACKNOWLEDGEMENTS
* http://dis.cs.umass.edu/~wagner/threads_html/sect2.html
*http://www.math.arizona.edu/swig/pthreads/threads.html#news
*/
#include <sys/types.h>
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
void pr_my_id( void *arg )
{
int myid = * (int *) arg;
printf ("Thread %d reporting\n", myid);
}
main()
{
pthread_t t1, t2, t3;
int id1 = 1,
id2 = 2,
id3 = 3;
int err;
pid_t pid;
/* Start three threads ... */
pthread_create ( &t1, NULL, (void *) &pr_my_id, (void *) &id1 );
pthread_create ( &t2, NULL, (void *) &pr_my_id, (void *) &id2 );
pthread_create ( &t3, NULL, (void *) &pr_my_id, (void *) &id3 );
/* Join them in order. */
if ( err = pthread_join(t1, NULL) )
printf ("join of t1 failed\n");
if ( err = pthread_join(t2, NULL) )
printf ("join of t2 failed\n");
if ( err = pthread_join(t3, NULL) )
printf ("join of t3 failed\n");
/*
sleep(1);
*/
pid = fork();
if (pid == -1)
printf ("fork() failed\n");
else
{
if (pid)
{
int status;
printf("I am the parent\n");
waitpid(pid, &status, 0);
}
else
{
printf("I am the child\n");
sleep(1);
exit(0);
}
}
printf ("Done\n");
exit(0);
}