pthread_detach.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_DETACH(3) manual page</TITLE>
  6. <META NAME="GENERATOR" CONTENT="OpenOffice.org 2.0 (Linux)">
  7. <META NAME="CREATED" CONTENT="20050504;18010700">
  8. <META NAME="CHANGEDBY" CONTENT="Ross Johnson">
  9. <META NAME="CHANGED" CONTENT="20060408;9255600">
  10. <!-- manual page source format generated by PolyglotMan v3.2, -->
  11. <!-- available at http://polyglotman.sourceforge.net/ -->
  12. </HEAD>
  13. <BODY LANG="en-GB" BGCOLOR="#ffffff" DIR="LTR">
  14. <H4>POSIX Threads for Windows – REFERENCE - <A HREF="http://sources.redhat.com/pthreads-win32">Pthreads-w32</A></H4>
  15. <P><A HREF="index.html">Reference Index</A></P>
  16. <P><A HREF="#toc">Table of Contents</A></P>
  17. <H2><A HREF="#toc0" NAME="sect0">Name</A></H2>
  18. <P>pthread_detach - put a running thread in the detached state
  19. </P>
  20. <H2><A HREF="#toc1" NAME="sect1">Synopsis</A></H2>
  21. <P><B>#include &lt;pthread.h&gt;</B>
  22. </P>
  23. <P><B>int pthread_detach(pthread_t </B><I>th</I><B>);</B>
  24. </P>
  25. <H2><A HREF="#toc2" NAME="sect2">Description</A></H2>
  26. <P><B>pthread_detach</B> puts the thread <I>th</I> in the detached
  27. state. This guarantees that the resources consumed by <I>th</I> will
  28. be freed immediately when <I>th</I> terminates. However, this
  29. prevents other threads from synchronizing on the termination of <I>th</I>
  30. using <B>pthread_join</B>. If, when <B>pthread_detach</B> is called,
  31. <I>th</I> has already terminated, all of <I>th</I>'s remaining
  32. resources will be freed.</P>
  33. <P>A thread can be created initially in the detached state, using the
  34. <B>detachstate</B> attribute to <A HREF="pthread_create.html"><B>pthread_create</B>(3)</A>
  35. . In contrast, <B>pthread_detach</B> applies to threads created in
  36. the joinable state, and which need to be put in the detached state
  37. later.
  38. </P>
  39. <P>After <B>pthread_detach</B> completes, subsequent attempts to
  40. perform <B>pthread_join</B> on <I>th</I> will fail. If another thread
  41. is already joining the thread <I>th</I> at the time <B>pthread_detach</B>
  42. is called, <I>th</I> will be detached and <B>pthread_join</B> will
  43. eventually return when <I>th</I> terminates but may not return with
  44. <I>th</I>'s correct return code.
  45. </P>
  46. <H2><A HREF="#toc3" NAME="sect3">Return Value</A></H2>
  47. <P>On success, 0 is returned. On error, a non-zero error code is
  48. returned.
  49. </P>
  50. <H2><A HREF="#toc4" NAME="sect4">Errors</A></H2>
  51. <DL>
  52. <DT><B>ESRCH</B>
  53. </DT><DD>
  54. No thread could be found corresponding to that specified by <I>th</I>
  55. </DD><DT>
  56. <B>EINVAL</B>
  57. </DT><DD STYLE="margin-bottom: 0.5cm">
  58. the thread <I>th</I> is already in the detached state
  59. </DD></DL>
  60. <H2>
  61. <A HREF="#toc5" NAME="sect5">Author</A></H2>
  62. <P>Xavier Leroy &lt;[email protected]&gt;
  63. </P>
  64. <P>Modified by Ross Johnson for use with Pthreads-w32.</P>
  65. <H2><A HREF="#toc6" NAME="sect6">See Also</A></H2>
  66. <P><A HREF="pthread_create.html"><B>pthread_create</B>(3)</A> ,
  67. <A HREF="pthread_join.html"><B>pthread_join</B>(3)</A> ,
  68. <A HREF="pthread_attr_init.html"><B>pthread_attr_setdetachstate</B>(3)</A>
  69. </P>
  70. <HR>
  71. <P><A NAME="toc"></A><B>Table of Contents</B></P>
  72. <UL>
  73. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect0" NAME="toc0">Name</A>
  74. </P>
  75. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect1" NAME="toc1">Synopsis</A>
  76. </P>
  77. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect2" NAME="toc2">Description</A>
  78. </P>
  79. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect3" NAME="toc3">Return
  80. Value</A>
  81. </P>
  82. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect4" NAME="toc4">Errors</A>
  83. </P>
  84. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect5" NAME="toc5">Author</A>
  85. </P>
  86. <LI><P><A HREF="#sect6" NAME="toc6">See Also</A>
  87. </P>
  88. </UL>
  89. </BODY>
  90. </HTML>