This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: GDB 5.1 TODO list


> > * Thread support.  Right now, as soon as a thread finishes and exits,
> >   you're hosed.  This problem is reported once a week or so.
> 
> One thing that is desparatly needed is a few good test cases.  It is
> hard to tell if thread support is getting better or worse :-(
> 
>         Andrew

I posted one in February which should help:

	http://sources.redhat.com/ml/bug-gdb/2000-02/msg00008.html

Below are four versions of that same idea, which test detached or joinable
threads, and exiting by calling pthread_exit() or just falling through.

This tests several forms of thread exiting, as well as the ability to
create a large number of threads (in a lifetime serially, not concurrently)
-- as MarkK explained to me,

> Be aware though, that GDB cannot handle a lot of threads right now.  It
> chokes on the thread ID's after that since they don't fit in 15 bits.  So
> you'll see something like:
> 
>    thread_db: map_id2thr failed: invalid thread handle
> 
> after 30 or so threads with your program.
> 
> Mark

IMHO it's important to both handle thread exit and have a lifetime budget
of more than a few dozen threads.

--grg


===========================================================================

////
//// detached, pthread_exit()
////

#include <pthread.h>
#include <stdio.h>
#include <assert.h>

#define NTHREADS 100000
#define PRINTEVERY 10000

// committing the grossness of putting an int where a void* is expected.
void* exitImmediately(void* count)
{
    if ((int)count % PRINTEVERY == 0)
	printf("%d\n",(int)count);
    pthread_exit(NULL);
}

int main()
{
    pthread_t pthread;
    pthread_attr_t attr;
    int retval;
    int i;

    // set up attr to detach
    retval = pthread_attr_init(&attr);
    assert(retval==0);		// success
    retval = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
    assert(retval==0);		// success

    for (i=0; i<NTHREADS; ++i)
	pthread_create(&pthread, &attr, exitImmediately, (void*)i);
}

===========================================================================

////
//// detached, fall through
////

#include <pthread.h>
#include <stdio.h>
#include <assert.h>

#define NTHREADS 100000
#define PRINTEVERY 10000

// committing the grossness of putting an int where a void* is expected.
void* exitImmediately(void* count)
{
    if ((int)count % PRINTEVERY == 0)
	printf("%d\n",(int)count);
    return NULL;
}

int main()
{
    pthread_t pthread;
    pthread_attr_t attr;
    int retval;
    int i;

    // set up attr to detach
    retval = pthread_attr_init(&attr);
    assert(retval==0);		// success
    retval = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
    assert(retval==0);		// success

    for (i=0; i<NTHREADS; ++i)
	pthread_create(&pthread, &attr, exitImmediately, (void*)i);
}

===========================================================================

////
//// joinable, pthread_exit()
////

#include <stdio.h>
#include <pthread.h>

#define NTHREADS 10000

// committing the grossness of putting an int where a void* is expected.
void* exitImmediately(void* count)
{
    printf("tid %d: I'm #%d\n", pthread_self(), (int)count);
    pthread_exit(NULL);
}

int main(int argc, char* argv[])
{
    pthread_t p_thread;
    int i, retCreate, retJoin;

    for (i=0; i<NTHREADS; ++i) {
	retCreate = pthread_create(&p_thread, NULL, exitImmediately, (void*)i);
	if (retCreate == 0) {
	    retJoin = pthread_join(p_thread, NULL);
	}
	printf("spawned %d, return code %d, join returned %d\n", i,
	       retCreate, retJoin);
    }
}

===========================================================================

////
//// joinable, fall through
////

#include <stdio.h>
#include <pthread.h>

#define NTHREADS 10000

// committing the grossness of putting an int where a void* is expected.
void* exitImmediately(void* count)
{
    printf("tid %d: I'm #%d\n", pthread_self(), (int)count);
    return NULL;
}

int main(int argc, char* argv[])
{
    pthread_t p_thread;
    int i, retCreate, retJoin;

    for (i=0; i<NTHREADS; ++i) {
	retCreate = pthread_create(&p_thread, NULL, exitImmediately, (void*)i);
	if (retCreate == 0) {
	    retJoin = pthread_join(p_thread, NULL);
	}
	printf("spawned %d, return code %d, join returned %d\n", i,
	       retCreate, retJoin);
    }
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]