Bug 4376 - pthread_join does not return the values stated in the man page
Summary: pthread_join does not return the values stated in the man page
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 2.2-STABLE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 1997-08-25 04:40 UTC by bradley
Modified: 1997-11-25 01:30 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bradley 1997-08-25 04:40:02 UTC
The pthread_join() function from libc_r returns -1 if an error occurs and sets the global variable
		errno. This is contrary to what the man page states, and also contrary to my understanding of the proper
		behavior of Pthreads.

Fix: 

Fix src/lib/libc_r/uthread/uthread_join.c to return errors directly instead of setting errno. This behavior might
	exist elsewhere in libc_r...I am new to threads and this was actually the first program using Pthreads I tried.
	Library code scares me so I can't provide a diff, sorry. :)
How-To-Repeat: /*
 * thread_error.c
 *
 * Demonstrate detection of errors from a typical POSIX 1003.1c-1995
 * function, pthread_join.
 *
 * Code from _Programming with POSIX Threads_, by David R. Butenhof. Pp. 32-33
 * On FreeBSD this produces the following output:
 * bradley@ns2: {11} % ./thread_error
 * error -1: Unknown error: -1
 * thus demonstrating that -1 is being returned, instead of the proper ESRCH. Examining the source in
 * src/lib/libc_r/uthread/uthread_join.c it is obvious that pthread_join is not doing what the man page (and POSIX) say it
 * should.
 */
#include <pthread.h>
#include <stdio.h>
#include <string.h>

int main (int argc, char *argv[])
{
    pthread_t thread;
    int status;

    /*
     * Attempt to join with an uninitialized thread ID. On most
     * implementations, this will return an ESRCH error code. If
     * the local (and uninitialized) pthread_t happens to be a valid
     * thread ID, it is almost certainly that of the initial thread,
     * which is running main(). In that case, your Pthreads
     * implementation may either return EDEADLK (self-deadlock),
     * or it may hang. If it hangs, quit and try again.
     */
    status = pthread_join (thread, NULL);
    if (status != 0)
        fprintf (stderr, "error %d: %s\n", status, strerror (status));
    return status;
}
Comment 1 alex freebsd_committer freebsd_triage 1997-11-25 01:29:28 UTC
State Changed
From-To: open->closed

Fixed in rev 1.3 of uthread_join.c.