This is the mail archive of the gdb-prs@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]
Other format: [Raw text]

gdb/946: threads (from pthreads) stay in defunct state


>Number:         946
>Category:       gdb
>Synopsis:       threads (from pthreads) stay in defunct state
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jan 17 12:28:01 PST 2003
>Closed-Date:
>Last-Modified:
>Originator:     nicolas@activebuddy.com
>Release:        GNU gdb Red Hat Linux (5.2-2)
>Organization:
>Environment:
RH gcc-2.96-85
>Description:
Running this test app will keep former threads as "defunct" when run from gdb, whereas running the app by itself will terminate the threads properly.

This is a very bad problem when debugging a program that creates/destroys threads on the fly as it will fail when reaching 1024 thread create/destroy cycles.

>How-To-Repeat:
Compile the test case with "gcc -lpthread detach.cpp"
run it ./a.out &
and do a ps -x several times to see that after a few seconds, there are no threads running (only thread manager and main).

Then run again from gdb
when the test case calls abort, notice that info threads doesn't display any threads (correct), but that ps -x will show defunct threads.

---- cut detach.cpp ----
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>

pthread_mutex_t global_count = PTHREAD_MUTEX_INITIALIZER;
int count = 0;

void *thread_main(void *arg) {
        pthread_mutex_lock(&global_count);
        count++;
        pthread_mutex_unlock(&global_count);

        sleep(2);

        pthread_mutex_lock(&global_count);
        count--;
        pthread_mutex_unlock(&global_count);

        return NULL;
}

int main(int argc, char **argv) {
        pthread_t tid;
        int i;
        for(i=0; i < 10; i++) {
                int res;
                res = pthread_create(&tid, NULL, thread_main, NULL);
                if (res != 0) {
                        puts("Oups... could not create thread\n");
                        exit(-1);
                }
                res = pthread_detach(tid);
                if (res != 0) {
                        puts("could not detach thread!\n");
                        exit(-2);
                }
        }
        pthread_mutex_lock(&global_count);
        printf("count = %d\n", count);
        pthread_mutex_unlock(&global_count);
        sleep(5);

        /* all threads should be done at this point */

        {
                int *pp = 0;
                pthread_mutex_lock(&global_count);
                printf("count = %d\n", count);
                abort();
        }
}

---- end cut ----
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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