From owner-freebsd-bugs  Sun Aug 24 20:40:07 1997
Return-Path: <owner-freebsd-bugs>
Received: (from root@localhost)
          by hub.freebsd.org (8.8.7/8.8.7) id UAA12831
          for bugs-outgoing; Sun, 24 Aug 1997 20:40:07 -0700 (PDT)
Received: (from gnats@localhost)
          by hub.freebsd.org (8.8.7/8.8.7) id UAA12807;
          Sun, 24 Aug 1997 20:40:04 -0700 (PDT)
Resent-Date: Sun, 24 Aug 1997 20:40:04 -0700 (PDT)
Resent-Message-Id: <199708250340.UAA12807@hub.freebsd.org>
Resent-From: gnats (GNATS Management)
Resent-To: freebsd-bugs
Resent-Reply-To: FreeBSD-gnats@FreeBSD.ORG, bradley@dunn.org
Received: from ns2.harborcom.net (root@ns2.harborcom.net [206.158.4.4])
          by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id UAA12666
          for <FreeBSD-gnats-submit@freebsd.org>; Sun, 24 Aug 1997 20:38:47 -0700 (PDT)
Received: (from bradley@localhost)
	by ns2.harborcom.net (8.8.7/8.8.5) id XAA27380;
	Sun, 24 Aug 1997 23:38:45 -0400 (EDT)
Message-Id: <199708250338.XAA27380@ns2.harborcom.net>
Date: Sun, 24 Aug 1997 23:38:45 -0400 (EDT)
From: bradley@dunn.org
Reply-To: bradley@dunn.org
To: FreeBSD-gnats-submit@FreeBSD.ORG
X-Send-Pr-Version: 3.2
Subject: bin/4376: pthread_join does not return the correct values
Sender: owner-freebsd-bugs@FreeBSD.ORG
X-Loop: FreeBSD.org
Precedence: bulk


>Number:         4376
>Category:       bin
>Synopsis:       pthread_join does not return the values stated in the man page
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Aug 24 20:40:02 PDT 1997
>Last-Modified:
>Originator:     Bradley Dunn
>Organization:
Harbor Communications
>Release:        FreeBSD 2.2-STABLE i386
>Environment:
FreeBSD ns2.harborcom.net 2.2-STABLE FreeBSD 2.2-STABLE #0: Tue Aug  5 01:16:09 EDT 1997 dunn@ns2.harborcom.net:/usr/src/sys/compile/NS2  i386
>Description:
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.
>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;
}

>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. :)
>Audit-Trail:
>Unformatted: