threads/1585: pthread_create generates notify to semaphore when run under gdb

bbr@lampreynetworks.com bbr@lampreynetworks.com
Sun Mar 14 19:28:00 GMT 2004


>Number:         1585
>Category:       threads
>Synopsis:       pthread_create generates notify to semaphore when run under gdb
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sun Mar 14 19:28:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Barry Reinhold
>Release:        gdb version 6.0post-0.20031117.7rh
>Organization:
>Environment:
Fedora Core 2 test1, (also on RedHat 9.0)
i686
GNU GCC 3.3.2 20040119 (RedHat Linux 3.2.2-8)
glibc 2.3.3-7
>Description:
If a process spawns a thread and then calls sem_wait, if the spawned thread itself calls pthread_create, the parent process will return from the sem_wait call.

Code below produces the problem. The code is compiled with
g++ -g3 test.cxx -lpthread

and debugged with "gdb a.out"

code below
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <semaphore.h>
#include <pthread.h>
/*
 * pthread_create in gdb causes cancellation of sem_wait demo program.
 */
void *ib_listen(void *junk)
{
    sem_t *sem_two;
    pthread_attr_t attr;
    pthread_t thread;

    printf("In iblisten\n");
    sem_two = (sem_t *)malloc(sizeof(sem_t));
    while(1) {
        printf("thread ib_listen waiting on sem_two\n");
        sem_wait(sem_two);
        printf("thread ib_listen awoken...\n");
    }
}

void *vport(void *junk)
{
    sem_t *sem_one;
    pthread_attr_t attr;
    pthread_t thread;
    int retval;

    printf("In thread vport\n");
    sem_one = (sem_t *)malloc(sizeof(sem_t));
    sem_init(sem_one,0,0);
    pthread_attr_init(&attr);
    sleep(1);
    retval = pthread_create(&thread, &attr, ib_listen, NULL );
    while(1) {
        printf("thread vport waiting on sem_one\n");
        sem_wait(sem_one);
        printf("thread vport awoken...\n");
    }
}

int main(int argc, char **argv)
{
    sem_t *sem_main;
    pthread_attr_t attr;
    pthread_t thread;
    int retval;
    
    sem_main = (sem_t *)malloc(sizeof(sem_t));
    sem_init(sem_main,0,0);
    pthread_attr_init(&attr);
    retval = pthread_create(&thread, &attr, vport, NULL );
    printf("Main thread waiting on sem_main\n");
    sem_wait(sem_main);
    printf("Main thread has been woken up\n");
    sleep(10);
}
>How-To-Repeat:
compile program and run under gdb.
if "main thread has been woken up" is printed then failure has been reproduced. 
>Fix:

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



More information about the Gdb-prs mailing list