pthread_kill.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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_SIGNAL(3) manual page</TITLE>
  6. <META NAME="GENERATOR" CONTENT="OpenOffice.org 1.1.3 (Linux)">
  7. <META NAME="CREATED" CONTENT="20050504;18500100">
  8. <META NAME="CHANGED" CONTENT="20050504;23005800">
  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_sigmask, pthread_kill, sigwait - handling of signals in
  18. threads
  19. </P>
  20. <H2><A HREF="#toc1" NAME="sect1">Synopsis</A></H2>
  21. <P><B>#include &lt;pthread.h&gt;</B> <BR><B>#include &lt;signal.h&gt;</B>
  22. </P>
  23. <P><B>int pthread_sigmask(int </B><I>how</I><B>, const sigset_t
  24. *</B><I>newmask</I><B>, sigset_t *</B><I>oldmask</I><B>);</B>
  25. </P>
  26. <P><B>int pthread_kill(pthread_t </B><I>thread</I><B>, int </B><I>signo</I><B>);</B>
  27. </P>
  28. <P><B>int sigwait(const sigset_t *</B>set, <B>int</B> *sig);</P>
  29. <H2><A HREF="#toc2" NAME="sect2">Description</A></H2>
  30. <P><B>pthread_sigmask</B> changes the signal mask for the calling
  31. thread as described by the <I>how</I> and <I>newmask</I> arguments.
  32. If <I>oldmask</I> is not <B>NULL</B>, the previous signal mask is
  33. stored in the location pointed to by <I>oldmask</I>. <B>Pthreads-w32</B>
  34. implements this function but no other function uses the signal mask
  35. yet.</P>
  36. <P>The meaning of the <I>how</I> and <I>newmask</I> arguments is the
  37. same as for <B><SPAN STYLE="font-style: normal">sigprocmask</SPAN></B>(2).
  38. If <I>how</I> is <B>SIG_SETMASK</B>, the signal mask is set to
  39. <I>newmask</I>. If <I>how</I> is <B>SIG_BLOCK</B>, the signals
  40. specified to <I>newmask</I> are added to the current signal mask. If
  41. <I>how</I> is <B>SIG_UNBLOCK</B>, the signals specified to <I>newmask</I>
  42. are removed from the current signal mask.
  43. </P>
  44. <P>Recall that signal masks are set on a per-thread basis, but signal
  45. actions and signal handlers, as set with <B>sigaction</B>(2), are
  46. shared between all threads.
  47. </P>
  48. <P><B>pthread_kill</B> send signal number <I>signo</I> to the thread
  49. <I>thread</I>. <B>Pthreads-w32</B> only supports signal number 0,
  50. which does not send any signal but causes <B>pthread_kill</B> to
  51. return an error if <I>thread</I> is not valid.</P>
  52. <P><B>sigwait</B> suspends the calling thread until one of the
  53. signals in <I>set</I> is delivered to the calling thread. It then
  54. stores the number of the signal received in the location pointed to
  55. by <I>sig</I> and returns. The signals in <I>set</I> must be blocked
  56. and not ignored on entrance to <B>sigwait</B>. If the delivered
  57. signal has a signal handler function attached, that function is <I>not</I>
  58. called. <B>Pthreads-w32</B> implements this function as a
  59. cancellation point only - it does not wait for any signals and does
  60. not change the location pointed to by <I>sig</I>.</P>
  61. <H2><A HREF="#toc3" NAME="sect3">Cancellation</A></H2>
  62. <P><B>sigwait</B> is a cancellation point.
  63. </P>
  64. <H2><A HREF="#toc4" NAME="sect4">Return Value</A></H2>
  65. <P>On success, 0 is returned. On failure, a non-zero error code is
  66. returned.
  67. </P>
  68. <H2><A HREF="#toc5" NAME="sect5">Errors</A></H2>
  69. <P>The <B>pthread_sigmask</B> function returns the following error
  70. codes on error:
  71. </P>
  72. <DL>
  73. <DL>
  74. <DT STYLE="margin-right: 1cm; margin-bottom: 0.5cm"><B>EINVAL</B>
  75. </DT><DD STYLE="margin-right: 1cm; margin-bottom: 0.5cm">
  76. <I>how</I> is not one of <B>SIG_SETMASK</B>, <B>SIG_BLOCK</B>, or
  77. <B>SIG_UNBLOCK</B>
  78. </DD></DL>
  79. </DL>
  80. <P>
  81. The <B>pthread_kill</B> function returns the following error codes on
  82. error:
  83. </P>
  84. <DL>
  85. <DL>
  86. <DT STYLE="margin-right: 1cm; margin-bottom: 0.5cm"><B>EINVAL</B>
  87. </DT><DD STYLE="margin-right: 1cm; margin-bottom: 0.5cm">
  88. <I>signo</I> is not a valid signal number or is unsupported.</DD><DT STYLE="margin-right: 1cm; margin-bottom: 0.5cm">
  89. <B>ESRCH</B>
  90. </DT><DD STYLE="margin-right: 1cm; margin-bottom: 0.5cm">
  91. the thread <I>thread</I> does not exist (e.g. it has already
  92. terminated)
  93. </DD></DL>
  94. </DL>
  95. <P>
  96. The <B>sigwait</B> function never returns an error.
  97. </P>
  98. <H2><A HREF="#toc6" NAME="sect6">Author</A></H2>
  99. <P>Xavier Leroy &lt;[email protected]&gt;
  100. </P>
  101. <P>Modified by Ross Johnson for use with <A HREF="http://sources.redhat.com/pthreads-win32">Pthreads-w32</A>.</P>
  102. <H2><A HREF="#toc7" NAME="sect7">See Also</A></H2>
  103. <P>
  104. </P>
  105. <H2><A HREF="#toc8" NAME="sect8">Notes</A></H2>
  106. <P>In any implementation, for <B>sigwait</B> to work reliably, the
  107. signals being waited for must be blocked in all threads, not only in
  108. the calling thread, since otherwise the POSIX semantics for signal
  109. delivery do not guarantee that it’s the thread doing the <B>sigwait</B>
  110. that will receive the signal. The best way to achieve this is to
  111. block those signals before any threads are created, and never unblock
  112. them in the program other than by calling <B>sigwait</B>. This works
  113. because all threads inherit their initial sigmask from their creating
  114. thread.</P>
  115. <H2><A HREF="#toc9" NAME="sect9">Bugs</A></H2>
  116. <P><B>Pthreads-w32</B> does not implement signals yet and so these
  117. routines have almost no use except to prevent the compiler or linker
  118. from complaining. <B>pthread_kill</B> is useful in determining if the
  119. thread is a valid thread, but since many threads implementations
  120. reuse thread IDs, the valid thread may no longer be the thread you
  121. think it is, and so this method of determining thread validity is not
  122. portable, and very risky. <B>Pthreads-w32</B> from version 1.0.0
  123. onwards implements pseudo-unique thread IDs, so applications that use
  124. this technique (but really shouldn't) have some protection.</P>
  125. <HR>
  126. <P><A NAME="toc"></A><B>Table of Contents</B></P>
  127. <UL>
  128. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect0" NAME="toc0">Name</A>
  129. </P>
  130. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect1" NAME="toc1">Synopsis</A>
  131. </P>
  132. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect2" NAME="toc2">Description</A>
  133. </P>
  134. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect3" NAME="toc3">Cancellation</A>
  135. </P>
  136. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect4" NAME="toc4">Return
  137. Value</A>
  138. </P>
  139. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect5" NAME="toc5">Errors</A>
  140. </P>
  141. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect6" NAME="toc6">Author</A>
  142. </P>
  143. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect7" NAME="toc7">See
  144. Also</A>
  145. </P>
  146. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect8" NAME="toc8">Notes</A>
  147. </P>
  148. <LI><P><A HREF="#sect9" NAME="toc9">Bugs</A>
  149. </P>
  150. </UL>
  151. </BODY>
  152. </HTML>