Bug 91571 - pthread_join joins exitted thread
Summary: pthread_join joins exitted thread
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: glibc
Version: 9
Hardware: i586
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-05-24 16:17 UTC by Steve Grubb
Modified: 2016-11-24 14:54 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2003-05-26 10:47:10 UTC
Embargoed:


Attachments (Terms of Use)

Description Steve Grubb 2003-05-24 16:17:58 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.2.1) Gecko/20030225

Description of problem:
pthread_join returns success when joining a thread that has already exitted. It
should return ESRCH saying that it could not find the thread.

Version-Release number of selected component (if applicable):
glibc-2.3.2-27.9

How reproducible:
Always

Steps to Reproduce:
1. Compile and run the following program:

#include <stdio.h>
#include <pthread.h>
#include <errno.h>
 
void *a_thread_func()
{
        pthread_exit(0);
        return NULL;
}
 
int main(void)
{
        pthread_t new_th;
        int ret;
                                                                                
        if (pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) {
                perror("Error creating thread\n");
                return 1;
        }
                                                                                
        if ( pthread_join(new_th, NULL) !=0 ) {
                perror("Error in pthread_join()\n");
                return 1;
        }
                                                                                
        if ( (ret=pthread_join(new_th, NULL)) != ESRCH) {
                printf("Return code should be ESRCH, but is: %d.\n", ret);
                return 1;
        }
        return 0;
}


Actual Results:  Return code should be ESRCH, but is: 0.

Expected Results:  No output from the program.

Comment 1 Jakub Jelinek 2003-05-26 10:47:10 UTC
This is ill formed. E.g. POSIX 2001, System Interfaces 2.9.2 allows thread IDs
to be reused after pthread_join, essentially what you're trying to do
is the same as accessing memory after free on it has been called.


Note You need to log in before you can comment on or make changes to this bug.