pthread_join.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8">
  5. <TITLE>PTHREAD_JOIN(3) manual page</TITLE>
  6. <META NAME="GENERATOR" CONTENT="OpenOffice.org 1.1.3 (Linux)">
  7. <META NAME="CREATED" CONTENT="20050504;18232700">
  8. <META NAME="CHANGED" CONTENT="20050504;18421400">
  9. <!-- manual page source format generated by PolyglotMan v3.2, -->
  10. <!-- available at http://polyglotman.sourceforge.net/ -->
  11. </HEAD>
  12. <BODY LANG="en-GB" BGCOLOR="#ffffff" DIR="LTR">
  13. <H4>POSIX Threads for Windows – REFERENCE - <A HREF="http://sources.redhat.com/pthreads-win32">Pthreads-w32</A></H4>
  14. <P><A HREF="index.html">Reference Index</A></P>
  15. <P><A HREF="#toc">Table of Contents</A></P>
  16. <H2><A HREF="#toc0" NAME="sect0">Name</A></H2>
  17. <P>pthread_join - wait for termination of another thread
  18. </P>
  19. <H2><A HREF="#toc1" NAME="sect1">Synopsis</A></H2>
  20. <P><B>#include &lt;pthread.h&gt;</B>
  21. </P>
  22. <P><B>int pthread_join(pthread_t </B><I>th</I><B>, void
  23. **</B><I>thread_return</I><B>);</B>
  24. </P>
  25. <H2><A HREF="#toc2" NAME="sect2">Description</A></H2>
  26. <P><B>pthread_join</B> suspends the execution of the calling thread
  27. until the thread identified by <I>th</I> terminates, either by
  28. calling <A HREF="pthread_exit.html"><B>pthread_exit</B>(3)</A> or by
  29. being cancelled.
  30. </P>
  31. <P>If <I>thread_return</I> is not <B>NULL</B>, the return value of <I>th</I>
  32. is stored in the location pointed to by <I>thread_return</I>. The
  33. return value of <I>th</I> is either the argument it gave to
  34. <A HREF="pthread_exit.html"><B>pthread_exit</B>(3)</A> , or
  35. <B>PTHREAD_CANCELED</B> if <I>th</I> was cancelled.
  36. </P>
  37. <P>The joined thread <B>th</B> must be in the joinable state: it must
  38. not have been detached using <A HREF="pthread_detach.html"><B>pthread_detach</B>(3)</A>
  39. or the <B>PTHREAD_CREATE_DETACHED</B> attribute to <A HREF="pthread_create.html"><B>pthread_create</B>(3)</A>
  40. .
  41. </P>
  42. <P>When a joinable thread terminates, its memory resources (thread
  43. descriptor and stack) are not deallocated until another thread
  44. performs <B>pthread_join</B> on it. Therefore, <B>pthread_join</B>
  45. must be called once for each joinable thread created to avoid memory
  46. leaks.
  47. </P>
  48. <P>At most one thread can wait for the termination of a given thread.
  49. Calling <B>pthread_join</B> on a thread <I>th</I> on which another
  50. thread is already waiting for termination returns an error.
  51. </P>
  52. <H2><A HREF="#toc3" NAME="sect3">Cancellation</A></H2>
  53. <P><B>pthread_join</B> is a cancellation point. If a thread is
  54. cancelled while suspended in <B>pthread_join</B>, the thread
  55. execution resumes immediately and the cancellation is executed
  56. without waiting for the <I>th</I> thread to terminate. If
  57. cancellation occurs during <B>pthread_join</B>, the <I>th</I> thread
  58. remains not joined.
  59. </P>
  60. <H2><A HREF="#toc4" NAME="sect4">Return Value</A></H2>
  61. <P>On success, the return value of <I>th</I> is stored in the
  62. location pointed to by <I>thread_return</I>, and 0 is returned. On
  63. error, a non-zero error code is returned.
  64. </P>
  65. <H2><A HREF="#toc5" NAME="sect5">Errors</A></H2>
  66. <DL>
  67. <DT><B>ESRCH</B>
  68. </DT><DD>
  69. No thread could be found corresponding to that specified by <I>th</I>.
  70. </DD><DT>
  71. <B>EINVAL</B>
  72. </DT><DD>
  73. The <I>th</I> thread has been detached.
  74. </DD><DT>
  75. <B>EINVAL</B>
  76. </DT><DD>
  77. Another thread is already waiting on termination of <I>th</I>.
  78. </DD><DT>
  79. <B>EDEADLK</B>
  80. </DT><DD STYLE="margin-bottom: 0.5cm">
  81. The <I>th</I> argument refers to the calling thread.
  82. </DD></DL>
  83. <H2>
  84. <A HREF="#toc6" NAME="sect6">Author</A></H2>
  85. <P>Xavier Leroy &lt;[email protected]&gt;
  86. </P>
  87. <H2><A HREF="#toc7" NAME="sect7">See Also</A></H2>
  88. <P><A HREF="pthread_exit.html"><B>pthread_exit</B>(3)</A> ,
  89. <A HREF="pthread_detach.html"><B>pthread_detach</B>(3)</A> ,
  90. <A HREF="pthread_create.html"><B>pthread_create</B>(3)</A> ,
  91. <A HREF="pthread_attr_setdetachstate.html"><B>pthread_attr_setdetachstate</B>(3)</A>
  92. , <A HREF="pthread_cleanup_push.html"><B>pthread_cleanup_push</B>(3)</A>
  93. , <A HREF="pthread_key_create.html"><B>pthread_key_create</B>(3)</A>
  94. .
  95. </P>
  96. <HR>
  97. <P><A NAME="toc"></A><B>Table of Contents</B></P>
  98. <UL>
  99. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect0" NAME="toc0">Name</A>
  100. </P>
  101. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect1" NAME="toc1">Synopsis</A>
  102. </P>
  103. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect2" NAME="toc2">Description</A>
  104. </P>
  105. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect3" NAME="toc3">Cancellation</A>
  106. </P>
  107. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect4" NAME="toc4">Return
  108. Value</A>
  109. </P>
  110. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect5" NAME="toc5">Errors</A>
  111. </P>
  112. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect6" NAME="toc6">Author</A>
  113. </P>
  114. <LI><P><A HREF="#sect7" NAME="toc7">See Also</A>
  115. </P>
  116. </UL>
  117. </BODY>
  118. </HTML>