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; }
State Changed From-To: open->closed Fixed in rev 1.3 of uthread_join.c.