pthread_attr_init.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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_ATTR_INIT(3) manual page</TITLE>
  6. <META NAME="GENERATOR" CONTENT="OpenOffice.org 1.1.3 (Linux)">
  7. <META NAME="CREATED" CONTENT="20050504;10092900">
  8. <META NAME="CHANGED" CONTENT="20050505;16540200">
  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_attr_init, pthread_attr_destroy,
  18. pthread_attr_setdetachstate, pthread_attr_getdetachstate,
  19. pthread_attr_setschedparam, pthread_attr_getschedparam,
  20. pthread_attr_setschedpolicy, pthread_attr_getschedpolicy,
  21. pthread_attr_setinheritsched, pthread_attr_getinheritsched,
  22. pthread_attr_setscope, pthread_attr_getscope - thread creation
  23. attributes
  24. </P>
  25. <H2><A HREF="#toc1" NAME="sect1">Synopsis</A></H2>
  26. <P><B>#include &lt;pthread.h&gt;</B>
  27. </P>
  28. <P><B>int pthread_attr_init(pthread_attr_t *</B><I>attr</I><B>);</B>
  29. </P>
  30. <P><B>int pthread_attr_destroy(pthread_attr_t *</B><I>attr</I><B>);</B>
  31. </P>
  32. <P><B>int pthread_attr_setdetachstate(pthread_attr_t *</B><I>attr</I><B>,
  33. int </B><I>detachstate</I><B>);</B>
  34. </P>
  35. <P><B>int pthread_attr_getdetachstate(const pthread_attr_t *</B><I>attr</I><B>,
  36. int *</B><I>detachstate</I><B>);</B>
  37. </P>
  38. <P><B>int pthread_attr_setschedpolicy(pthread_attr_t *</B><I>attr</I><B>,
  39. int </B><I>policy</I><B>);</B>
  40. </P>
  41. <P><B>int pthread_attr_getschedpolicy(const pthread_attr_t *</B><I>attr</I><B>,
  42. int *</B><I>policy</I><B>);</B>
  43. </P>
  44. <P><B>int pthread_attr_setschedparam(pthread_attr_t *</B><I>attr</I><B>,
  45. const struct sched_param *</B><I>param</I><B>);</B>
  46. </P>
  47. <P><B>int pthread_attr_getschedparam(const pthread_attr_t *</B><I>attr</I><B>,
  48. struct sched_param *</B><I>param</I><B>);</B>
  49. </P>
  50. <P><B>int pthread_attr_setinheritsched(pthread_attr_t *</B><I>attr</I><B>,
  51. int </B><I>inherit</I><B>);</B>
  52. </P>
  53. <P><B>int pthread_attr_getinheritsched(const pthread_attr_t *</B><I>attr</I><B>,
  54. int *</B><I>inherit</I><B>);</B>
  55. </P>
  56. <P><B>int pthread_attr_setscope(pthread_attr_t *</B><I>attr</I><B>,
  57. int </B><I>scope</I><B>);</B>
  58. </P>
  59. <P><B>int pthread_attr_getscope(const pthread_attr_t *</B><I>attr</I><B>,
  60. int *</B><I>scope</I><B>);</B>
  61. </P>
  62. <H2><A HREF="#toc2" NAME="sect2">Description</A></H2>
  63. <P>Setting attributes for threads is achieved by filling a thread
  64. attribute object <I>attr</I> of type <B>pthread_attr_t</B>, then
  65. passing it as second argument to <A HREF="pthread_create.html"><B>pthread_create</B>(3)</A>
  66. . Passing <B>NULL</B> is equivalent to passing a thread attribute
  67. object with all attributes set to their default values.
  68. </P>
  69. <P><B>pthread_attr_init</B> initializes the thread attribute object
  70. <I>attr</I> and fills it with default values for the attributes. (The
  71. default values are listed below for each attribute.)
  72. </P>
  73. <P>Each attribute <I>attrname</I> (see below for a list of all
  74. attributes) can be individually set using the function
  75. <B>pthread_attr_set</B><I>attrname</I> and retrieved using the
  76. function <B>pthread_attr_get</B><I>attrname.</I>
  77. </P>
  78. <P><B>pthread_attr_destroy</B> destroys a thread attribute object,
  79. which must not then be reused until it is reinitialized.
  80. </P>
  81. <P>Attribute objects are consulted only when creating a new thread.
  82. The same attribute object can be used for creating several threads.
  83. Modifying an attribute object after a call to <B>pthread_create</B>
  84. does not change the attributes of the thread previously created.
  85. </P>
  86. <P>The following thread attributes are supported:
  87. </P>
  88. <H3><A HREF="#toc3" NAME="sect3">detachstate</A></H3>
  89. <P>Control whether the thread is created in the joinable state (value
  90. <B>PTHREAD_CREATE_JOINABLE</B>) or in the detached state (
  91. <B>PTHREAD_CREATE_DETACHED</B>).
  92. </P>
  93. <P>Default value: <B>PTHREAD_CREATE_JOINABLE</B>.
  94. </P>
  95. <P>In the joinable state, another thread can synchronize on the
  96. thread termination and recover its termination code using
  97. <A HREF="pthread_join.html"><B>pthread_join</B>(3)</A> . When a
  98. joinable thread terminates, some of the thread resources are kept
  99. allocated, and released only when another thread performs
  100. <A HREF="pthread_join.html"><B>pthread_join</B>(3)</A> on that
  101. thread.
  102. </P>
  103. <P>In the detached state, the thread's resources are released
  104. immediately when it terminates. <A HREF="pthread_join.html"><B>pthread_join</B>(3)</A>
  105. cannot be used to synchronize on the thread termination.
  106. </P>
  107. <P>A thread created in the joinable state can later be put in the
  108. detached thread using <A HREF="pthread_detach.html"><B>pthread_detach</B>(3)</A>
  109. .
  110. </P>
  111. <H3><A HREF="#toc4" NAME="sect4">schedpolicy</A></H3>
  112. <P>Select the scheduling policy for the thread: one of <B>SCHED_OTHER</B>
  113. (regular, non-real-time scheduling), <B>SCHED_RR</B> (real-time,
  114. round-robin) or <B>SCHED_FIFO</B> (real-time, first-in first-out).
  115. </P>
  116. <P><B>Pthreads-w32</B> only supports <B>SCHED_OTHER</B> - attempting
  117. to set one of the other policies will return an error ENOTSUP.</P>
  118. <P>Default value: <B>SCHED_OTHER</B>.
  119. </P>
  120. <P><B>Pthreads-w32</B> only supports <B>SCHED_OTHER</B> - attempting
  121. to set one of the other policies will return an error ENOTSUP.</P>
  122. <P>The scheduling policy of a thread can be changed after creation
  123. with <A HREF="pthread_setschedparam.html"><B>pthread_setschedparam</B>(3)</A>
  124. .
  125. </P>
  126. <H3><A HREF="#toc5" NAME="sect5">schedparam</A></H3>
  127. <P>Contain the scheduling parameters (essentially, the scheduling
  128. priority) for the thread.</P>
  129. <P><B>Pthreads-w32</B> supports the priority levels defined by the
  130. Windows system it is running on. Under Windows, thread priorities are
  131. relative to the process priority class, which must be set via the
  132. Windows W32 API.</P>
  133. <P>Default value: priority is 0 (Win32 level <B>THREAD_PRIORITY_NORMAL</B>).
  134. </P>
  135. <P>The scheduling priority of a thread can be changed after creation
  136. with <A HREF="pthread_setschedparam.html"><B>pthread_setschedparam</B>(3)</A>
  137. .
  138. </P>
  139. <H3><A HREF="#toc6" NAME="sect6">inheritsched</A></H3>
  140. <P>Indicate whether the scheduling policy and scheduling parameters
  141. for the newly created thread are determined by the values of the
  142. <I>schedpolicy</I> and <I>schedparam</I> attributes (value
  143. <B>PTHREAD_EXPLICIT_SCHED</B>) or are inherited from the parent
  144. thread (value <B>PTHREAD_INHERIT_SCHED</B>).
  145. </P>
  146. <P>Default value: <B>PTHREAD_EXPLICIT_SCHED</B>.
  147. </P>
  148. <H3><A HREF="#toc7" NAME="sect7">scope</A></H3>
  149. <P>Define the scheduling contention scope for the created thread. The
  150. only value supported in the <B>Pthreads-w32</B> implementation is
  151. <B>PTHREAD_SCOPE_SYSTEM</B>, meaning that the threads contend for CPU
  152. time with all processes running on the machine. The other value
  153. specified by the standard, <B>PTHREAD_SCOPE_PROCESS</B>, means that
  154. scheduling contention occurs only between the threads of the running
  155. process.</P>
  156. <P><B>Pthreads-w32</B> only supports <B>PTHREAD_SCOPE_SYSTEM</B>.</P>
  157. <P>Default value: <B>PTHREAD_SCOPE_SYSTEM</B>.
  158. </P>
  159. <H2><A HREF="#toc8" NAME="sect8">Return Value</A></H2>
  160. <P>All functions return 0 on success and a non-zero error code on
  161. error. On success, the <B>pthread_attr_get</B><I>attrname</I>
  162. functions also store the current value of the attribute <I>attrname</I>
  163. in the location pointed to by their second argument.
  164. </P>
  165. <H2><A HREF="#toc9" NAME="sect9">Errors</A></H2>
  166. <P>The <B>pthread_attr_setdetachstate</B> function returns the
  167. following error codes on error:
  168. </P>
  169. <DL>
  170. <DL>
  171. <DT STYLE="margin-right: 1cm; margin-bottom: 0.5cm"><B>EINVAL</B>
  172. </DT><DD STYLE="margin-right: 1cm; margin-bottom: 0.5cm">
  173. the specified <I>detachstate</I> is not one of
  174. <B>PTHREAD_CREATE_JOINABLE</B> or <B>PTHREAD_CREATE_DETACHED</B>.
  175. </DD></DL>
  176. </DL>
  177. <P>
  178. The <B>pthread_attr_setschedparam</B> function returns the following
  179. error codes on error:
  180. </P>
  181. <DL>
  182. <DL>
  183. <DT STYLE="margin-right: 1cm; margin-bottom: 0.5cm"><B>EINVAL</B>
  184. </DT><DD STYLE="margin-right: 1cm; margin-bottom: 0.5cm">
  185. the priority specified in <I>param</I> is outside the range of
  186. allowed priorities for the scheduling policy currently in <I>attr</I>
  187. (1 to 99 for <B>SCHED_FIFO</B> and <B>SCHED_RR</B>; 0 for
  188. <B>SCHED_OTHER</B>).
  189. </DD></DL>
  190. </DL>
  191. <P>
  192. The <B>pthread_attr_setschedpolicy</B> function returns the following
  193. error codes on error:
  194. </P>
  195. <DL>
  196. <DL>
  197. <DT STYLE="margin-right: 1cm; margin-bottom: 0.5cm"><B>EINVAL</B>
  198. </DT><DD STYLE="margin-right: 1cm; margin-bottom: 0.5cm">
  199. the specified <I>policy</I> is not one of <B>SCHED_OTHER</B>,
  200. <B>SCHED_FIFO</B>, or <B>SCHED_RR</B>.
  201. </DD><DT STYLE="margin-right: 1cm; margin-bottom: 0.5cm">
  202. <B>ENOTSUP</B>
  203. </DT><DD STYLE="margin-right: 1cm; margin-bottom: 0.5cm">
  204. <I>policy</I> is not <B>SCHED_OTHER</B>, the only value supported
  205. by <B>Pthreads-w32</B>.</DD></DL>
  206. </DL>
  207. <P>
  208. The <B>pthread_attr_setinheritsched</B> function returns the
  209. following error codes on error:
  210. </P>
  211. <DL>
  212. <DL>
  213. <DT STYLE="margin-right: 1cm; margin-bottom: 0.5cm"><B>EINVAL</B>
  214. </DT><DD STYLE="margin-right: 1cm; margin-bottom: 0.5cm">
  215. the specified <I>inherit</I> is not one of <B>PTHREAD_INHERIT_SCHED</B>
  216. or <B>PTHREAD_EXPLICIT_SCHED</B>.
  217. </DD></DL>
  218. </DL>
  219. <P>
  220. The <B>pthread_attr_setscope</B> function returns the following error
  221. codes on error:
  222. </P>
  223. <DL>
  224. <DL>
  225. <DT STYLE="margin-right: 1cm; margin-bottom: 0.5cm"><B>EINVAL</B>
  226. </DT><DD STYLE="margin-right: 1cm; margin-bottom: 0.5cm">
  227. the specified <I>scope</I> is not one of <B>PTHREAD_SCOPE_SYSTEM</B>
  228. or <B>PTHREAD_SCOPE_PROCESS</B>.
  229. </DD><DT STYLE="margin-right: 1cm; margin-bottom: 0.5cm">
  230. <B>ENOTSUP</B>
  231. </DT><DD STYLE="margin-right: 1cm; margin-bottom: 0.5cm">
  232. the specified <I>scope</I> is <B>PTHREAD_SCOPE_PROCESS</B> (not
  233. supported by <B>Pthreads-w32</B>).
  234. </DD></DL>
  235. </DL>
  236. <H2>
  237. <A HREF="#toc10" NAME="sect10">Author</A></H2>
  238. <P>Xavier Leroy &lt;[email protected]&gt;
  239. </P>
  240. <P>Modified by Ross Johnson for use with <A HREF="http://sources.redhat.com/pthreads-win32">Pthreads-w32</A>.</P>
  241. <H2><A HREF="#toc11" NAME="sect11">See Also</A></H2>
  242. <P><A HREF="pthread_create.html"><B>pthread_create</B>(3)</A> ,
  243. <A HREF="pthread_join.html"><B>pthread_join</B>(3)</A> ,
  244. <A HREF="pthread_detach.html"><B>pthread_detach</B>(3)</A> ,
  245. <A HREF="pthread_setschedparam.html"><B>pthread_setschedparam</B>(3)</A>
  246. .
  247. </P>
  248. <HR>
  249. <P><A NAME="toc"></A><B>Table of Contents</B></P>
  250. <UL>
  251. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect0" NAME="toc0">Name</A>
  252. </P>
  253. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect1" NAME="toc1">Synopsis</A>
  254. </P>
  255. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect2" NAME="toc2">Description</A>
  256. </P>
  257. <UL>
  258. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect3" NAME="toc3">detachstate</A>
  259. </P>
  260. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect4" NAME="toc4">schedpolicy</A>
  261. </P>
  262. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect5" NAME="toc5">schedparam</A>
  263. </P>
  264. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect6" NAME="toc6">inheritsched</A>
  265. </P>
  266. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect7" NAME="toc7">scope</A>
  267. </P>
  268. </UL>
  269. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect8" NAME="toc8">Return
  270. Value</A>
  271. </P>
  272. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect9" NAME="toc9">Errors</A>
  273. </P>
  274. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect10" NAME="toc10">Author</A>
  275. </P>
  276. <LI><P><A HREF="#sect11" NAME="toc11">See Also</A>
  277. </P>
  278. </UL>
  279. </BODY>
  280. </HTML>