NAME
          cthread_exit, cthread_detach, cthread_join - thread manipu-
          lation routines

     LIBRARY
          C Threads Library (libcthreads.a)

     SYNOPSIS
          #include <cthread.h>

          void cthread_exit( any_t res);

          RESULT cthread_detach( cthread_t t);

          RESULT cthread_join( cthread_t t, any_t *rptr);

     PARAMETERS
          res    specifies a result value to be returned

          t      specifies a thread to detach or join.

          rptr   a pointer to a variable to be assigned the return
                 value of thread t.

     DESCRIPTION
          cthread_exit() causes the currently executing thread to exit
          with the result value res. This is identical to having the
          forked function perform a "return" with the same value.

          Note that a thread which has exited may not be immediately
          returned to the pool of free threads.  In particular, if a
          thread has not been detached with cthread_detach(), the
          thread will not be returned to the free pool until it has
          been joined to another thread (with cthread_join()).  In
          this case, the value res will be the value stored into the
          variable pointed to by rptr in the cthread_join() call. How-
          ever, if the thread has been detached, the value res is
          ignored and the thread is returned to the pool of free
          threads immediately upon exiting.

          Note also that there is no way to kill a thread other than
          having it return or perform a cthread_exit().

          cthread_detach() exists to inform the thread library that
          the specified thread may be returned to the free pool when
          it exits.  If a thread has not been detached, it is not
          returned to the thread pool until a cthread_join() call
          claims its return value.  Once a thread has been detached,
          attempts to join it will fail.

          The cthread_join() function suspends the calling thread
          until the specified thread terminates.  If the specified
          thread has already exited, the calling thread proceeds
          without blocking.  If rptr is non-NULL, the variable it
          points to will be set to the result value of the joined
          thread.  A thread can be joined only once.

     DIAGNOSTICS
          cthread_detach() can return T_JOINING_OR_FREED if the speci-
          fied thread has been joined or has already terminated and
          been freed.  Otherwise it returns T_SUCCEED.

          cthread_join() will return T_CANNOT_JOIN_MYSELF if the
          specified thread and the current thread are the same,
          T_CANNOT_JOIN if the specified thread is detached, freed or
          already joined, and T_SUCCEED if the join is successful.

     SEE ALSO
          cthread_intro(3), cthread_fork(3)

     AUTHOR
          Cthreads was written and maintained by many people.
          This man page written by Greg Eisenhauer.