1 .\"
   2 .\" This file and its contents are supplied under the terms of the
   3 .\" Common Development and Distribution License ("CDDL"), version 1.0.
   4 .\" You may only use this file in accordance with the terms of version
   5 .\" 1.0 of the CDDL.
   6 .\"
   7 .\" A full copy of the text of the CDDL should have accompanied this
   8 .\" source.  A copy of the CDDL is also available via the Internet at
   9 .\" http://www.illumos.org/license/CDDL.
  10 .\"
  11 .\"
  12 .\" Copyright 2016 Joyent, Inc.
  13 .\"
  14 .Dd "Jan 13, 2015"
  15 .Dt THRD_JOIN 3C
  16 .Os
  17 .Sh NAME
  18 .Nm thrd_join
  19 .Nd wait for thread termination
  20 .Sh SYNOPSIS
  21 .In threads.h
  22 .Ft int
  23 .Fo thrd_join
  24 .Fa "thrd_t thrd"
  25 .Fa "int *res"
  26 .Fc
  27 .Sh DESCRIPTION
  28 The
  29 .Fn thrd_join
  30 function suspends the exection of the current thread and waits for the
  31 thread indicated by
  32 .Fa thrd
  33 to terminate and stores the exit status, as set by a call to
  34 .Xr thrd_exit 3C ,
  35 for that thread in
  36 .Fa res ,
  37 if
  38 .Fa res
  39 is non-null.
  40 The
  41 .Fa thrd
  42 argument must be a member of the current process and it cannot be
  43 detached.
  44 If
  45 .Fa thrd
  46 has already terminated and another caller has not called
  47 .Fn thrd_join
  48 then the exit status will be returned to the caller without blocking
  49 execution of the thread.
  50 .Pp
  51 If multiple threads call
  52 .Fn thrd_join
  53 on the same thread, then both will be suspended until that thread
  54 terminates; however, only one thread will return successfully and obtain
  55 the actual status and the other will instead return with an error.
  56 .Pp
  57 For additional information on the thread joining interfaces supported by
  58 the system, see
  59 .Xr pthread_join 3C
  60 and
  61 .Xr thr_join 3C .
  62 .Sh RETURN_VALUES
  63 Upon successful completion, the
  64 .Fn thrd_join
  65 function returns
  66 .Sy thrd_success
  67 and if
  68 .Fa res
  69 is a non-null pointer, it will be filled in with the exit status of
  70 .Fa thrd .
  71 If an error occurs,
  72 .Sy thrd_error
  73 will be returned.
  74 .Sh INTERFACE STABILITY
  75 .Sy Standard
  76 .Sh MT-LEVEL
  77 .Sy MT-Safe
  78 .Sh SEE ALSO
  79 .Xr pthread_join 3C ,
  80 .Xr thrd_create 3C ,
  81 .Xr thrd_detach 3C ,
  82 .Xr attributes 5 ,
  83 .Xr threads 5