Bug 91571

Summary: pthread_join joins exitted thread
Product: [Retired] Red Hat Linux Reporter: Steve Grubb <linux_4ever>
Component: glibcAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: Brian Brock <bbrock>
Severity: medium Docs Contact:
Priority: medium    
Version: 9CC: fweimer, mitr
Target Milestone: ---   
Target Release: ---   
Hardware: i586   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2003-05-26 10:47:10 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

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.