Date: Sun, 24 Aug 1997 23:38:45 -0400 (EDT) From: bradley@dunn.org To: FreeBSD-gnats-submit@FreeBSD.ORG Subject: bin/4376: pthread_join does not return the correct values Message-ID: <199708250338.XAA27380@ns2.harborcom.net> Resent-Message-ID: <199708250340.UAA12807@hub.freebsd.org>
index | next in thread | raw e-mail
>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:
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199708250338.XAA27380>
