re66.html 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <title>&lt;GThread&gt;: </title>
  6. <meta name="generator" content="DocBook XSL Stylesheets V1.79.2">
  7. <link rel="home" href="index.html" title="">
  8. <link rel="up" href="ch01.html" title="GLib">
  9. <link rel="prev" href="re65.html" title="&lt;%GLibTestSubprocessFlags&gt;">
  10. <link rel="next" href="re67.html" title="&lt;%GLibThreadError&gt;">
  11. <meta name="generator" content="GTK-Doc V1.33.1 (XML mode)">
  12. <link rel="stylesheet" href="style.css" type="text/css">
  13. </head>
  14. <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
  15. <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
  16. <td width="100%" align="left" class="shortcuts"></td>
  17. <td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
  18. <td><img src="up-insensitive.png" width="16" height="16" border="0"></td>
  19. <td><a accesskey="p" href="re65.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
  20. <td><a accesskey="n" href="re67.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
  21. </tr></table>
  22. <div class="refentry">
  23. <a name="id-1.1.67"></a><div class="titlepage"></div>
  24. <div class="refnamediv">
  25. <h2>&lt;GThread&gt;</h2>
  26. <p>&lt;GThread&gt;</p>
  27. </div>
  28. <div class="refsect1">
  29. <a name="id-1.1.67.2"></a><h2>Description</h2>
  30. <p>The <span class="type">GThread</span> struct represents a running thread. This struct
  31. is returned by <code class="function">g_thread_new()</code> or <code class="function">g_thread_try_new()</code>. You can
  32. obtain the <span class="type">GThread</span> struct representing the current thread by
  33. calling <code class="function">g_thread_self()</code>.
  34. </p>
  35. <p>GThread is refcounted, see <code class="function">g_thread_ref()</code> and <code class="function">g_thread_unref()</code>.
  36. The thread represented by it holds a reference while it is running,
  37. and <code class="function">g_thread_join()</code> consumes the reference that it is given, so
  38. it is normally not necessary to manage GThread references
  39. explicitly.
  40. </p>
  41. <p>The structure is opaque -- none of its fields may be directly
  42. accessed.</p>
  43. </div>
  44. <div class="refsect1">
  45. <a name="id-1.1.67.3"></a><h2>Functions</h2>
  46. <div class="refsect2">
  47. <a name="id-1.1.67.3.2"></a><h3>join</h3>
  48. <div class="informalexample"><pre class="programlisting">(define-values (%return) (thread:join self))
  49. </pre></div>
  50. <p>Waits until <em class="parameter"><code>thread</code></em> finishes, i.e. the function <em class="parameter"><code>func</code></em>, as
  51. given to <code class="function">g_thread_new()</code>, returns or <code class="function">g_thread_exit()</code> is called.
  52. If <em class="parameter"><code>thread</code></em> has already terminated, then <code class="function">g_thread_join()</code>
  53. returns immediately.
  54. </p>
  55. <p>Any thread can wait for any other thread by calling <code class="function">g_thread_join()</code>,
  56. not just its 'creator'. Calling <code class="function">g_thread_join()</code> from multiple threads
  57. for the same <em class="parameter"><code>thread</code></em> leads to undefined behaviour.
  58. </p>
  59. <p>The value returned by <em class="parameter"><code>func</code></em> or given to <code class="function">g_thread_exit()</code> is
  60. returned by this function.
  61. </p>
  62. <p><code class="function">g_thread_join()</code> consumes the reference to the passed-in <em class="parameter"><code>thread</code></em>.
  63. This will usually cause the <span class="type">GThread</span> struct and associated resources
  64. to be freed. Use <code class="function">g_thread_ref()</code> to obtain an extra reference if you
  65. want to keep the GThread alive beyond the <code class="function">g_thread_join()</code> call.</p>
  66. <div class="refsect3">
  67. <a name="id-1.1.67.3.2.7"></a><h4>Parameters</h4>
  68. <div class="informaltable"><table><tr>
  69. <td class="parameter_name"><p>thread</p></td>
  70. <td class="parameter_description">
  71. <p>a <span class="type">GThread</span></p>
  72. <p>Passed as <code class="code">self</code></p>
  73. </td>
  74. </tr></table></div>
  75. </div>
  76. </div>
  77. <div class="refsect2">
  78. <a name="id-1.1.67.3.3"></a><h3>ref</h3>
  79. <div class="informalexample"><pre class="programlisting">(define-values (%return) (thread:ref self))
  80. </pre></div>
  81. <p>Increase the reference count on <em class="parameter"><code>thread</code></em>.</p>
  82. <div class="refsect3">
  83. <a name="id-1.1.67.3.3.4"></a><h4>Parameters</h4>
  84. <div class="informaltable"><table><tr>
  85. <td class="parameter_name"><p>thread</p></td>
  86. <td class="parameter_description">
  87. <p>a <span class="type">GThread</span></p>
  88. <p>Passed as <code class="code">self</code></p>
  89. </td>
  90. </tr></table></div>
  91. </div>
  92. </div>
  93. <div class="refsect2">
  94. <a name="id-1.1.67.3.4"></a><h3>unref</h3>
  95. <div class="informalexample"><pre class="programlisting">(define-values () (thread:unref self))
  96. </pre></div>
  97. <p>Decrease the reference count on <em class="parameter"><code>thread</code></em>, possibly freeing all
  98. resources associated with it.
  99. </p>
  100. <p>Note that each thread holds a reference to its <span class="type">GThread</span> while
  101. it is running, so it is safe to drop your own reference to it
  102. if you don't need it anymore.</p>
  103. <div class="refsect3">
  104. <a name="id-1.1.67.3.4.5"></a><h4>Parameters</h4>
  105. <div class="informaltable"><table><tr>
  106. <td class="parameter_name"><p>thread</p></td>
  107. <td class="parameter_description">
  108. <p>a <span class="type">GThread</span></p>
  109. <p>Passed as <code class="code">self</code></p>
  110. </td>
  111. </tr></table></div>
  112. </div>
  113. </div>
  114. <div class="refsect2">
  115. <a name="id-1.1.67.3.5"></a><h3>thread:try-new</h3>
  116. <div class="informalexample"><pre class="programlisting">(define-values (%return) (thread:try-new name func data))
  117. </pre></div>
  118. <p>Undocumented</p>
  119. <div class="refsect3">
  120. <a name="id-1.1.67.3.5.4"></a><h4>Parameters</h4>
  121. <div class="informaltable"><table>
  122. <tr>
  123. <td class="parameter_name"><p>name</p></td>
  124. <td class="parameter_description">
  125. <p></p>
  126. <p>Passed as <code class="code">name</code></p>
  127. </td>
  128. </tr>
  129. <tr>
  130. <td class="parameter_name"><p>func</p></td>
  131. <td class="parameter_description">
  132. <p></p>
  133. <p>Passed as <code class="code">func</code></p>
  134. </td>
  135. </tr>
  136. <tr>
  137. <td class="parameter_name"><p>data</p></td>
  138. <td class="parameter_description">
  139. <p></p>
  140. <p>Passed as <code class="code">data</code></p>
  141. </td>
  142. </tr>
  143. </table></div>
  144. </div>
  145. </div>
  146. <div class="refsect2">
  147. <a name="id-1.1.67.3.6"></a><h3>thread:new</h3>
  148. <div class="informalexample"><pre class="programlisting">(define-values (%return) (thread:new name func data))
  149. </pre></div>
  150. <p>Undocumented</p>
  151. <div class="refsect3">
  152. <a name="id-1.1.67.3.6.4"></a><h4>Parameters</h4>
  153. <div class="informaltable"><table>
  154. <tr>
  155. <td class="parameter_name"><p>name</p></td>
  156. <td class="parameter_description">
  157. <p></p>
  158. <p>Passed as <code class="code">name</code></p>
  159. </td>
  160. </tr>
  161. <tr>
  162. <td class="parameter_name"><p>func</p></td>
  163. <td class="parameter_description">
  164. <p></p>
  165. <p>Passed as <code class="code">func</code></p>
  166. </td>
  167. </tr>
  168. <tr>
  169. <td class="parameter_name"><p>data</p></td>
  170. <td class="parameter_description">
  171. <p></p>
  172. <p>Passed as <code class="code">data</code></p>
  173. </td>
  174. </tr>
  175. </table></div>
  176. </div>
  177. </div>
  178. <div class="refsect2">
  179. <a name="id-1.1.67.3.7"></a><h3>thread:error-quark</h3>
  180. <div class="informalexample"><pre class="programlisting">(define-values (%return) (thread:error-quark))
  181. </pre></div>
  182. <p>Undocumented</p>
  183. </div>
  184. <div class="refsect2">
  185. <a name="id-1.1.67.3.8"></a><h3>thread:exit</h3>
  186. <div class="informalexample"><pre class="programlisting">(define-values () (thread:exit retval))
  187. </pre></div>
  188. <p>Terminates the current thread.
  189. </p>
  190. <p>If another thread is waiting for us using <code class="function">g_thread_join()</code> then the
  191. waiting thread will be woken up and get <em class="parameter"><code>retval</code></em> as the return value
  192. of <code class="function">g_thread_join()</code>.
  193. </p>
  194. <p>Calling <code class="function">g_thread_exit()</code> with a parameter <em class="parameter"><code>retval</code></em> is equivalent to
  195. returning <em class="parameter"><code>retval</code></em> from the function <em class="parameter"><code>func</code></em>, as given to <code class="function">g_thread_new()</code>.
  196. </p>
  197. <p>You must only call <code class="function">g_thread_exit()</code> from a thread that you created
  198. yourself with <code class="function">g_thread_new()</code> or related APIs. You must not call
  199. this function from a thread created with another threading library
  200. or or from within a <span class="type">GThreadPool</span>.</p>
  201. <div class="refsect3">
  202. <a name="id-1.1.67.3.8.7"></a><h4>Parameters</h4>
  203. <div class="informaltable"><table><tr>
  204. <td class="parameter_name"><p>retval</p></td>
  205. <td class="parameter_description">
  206. <p>the return value of this thread</p>
  207. <p>Passed as <code class="code">retval</code></p>
  208. </td>
  209. </tr></table></div>
  210. </div>
  211. </div>
  212. <div class="refsect2">
  213. <a name="id-1.1.67.3.9"></a><h3>thread:self</h3>
  214. <div class="informalexample"><pre class="programlisting">(define-values (%return) (thread:self))
  215. </pre></div>
  216. <p>This function returns the <span class="type">GThread</span> corresponding to the
  217. current thread. Note that this function does not increase
  218. the reference count of the returned struct.
  219. </p>
  220. <p>This function will return a <span class="type">GThread</span> even for threads that
  221. were not created by GLib (i.e. those created by other threading
  222. APIs). This may be useful for thread identification purposes
  223. (i.e. comparisons) but you must not use GLib functions (such
  224. as <code class="function">g_thread_join()</code>) on these threads.</p>
  225. </div>
  226. <div class="refsect2">
  227. <a name="id-1.1.67.3.10"></a><h3>thread:yield</h3>
  228. <div class="informalexample"><pre class="programlisting">(define-values () (thread:yield))
  229. </pre></div>
  230. <p>Causes the calling thread to voluntarily relinquish the CPU, so
  231. that other threads can run.
  232. </p>
  233. <p>This function is often used as a method to make busy wait less evil.</p>
  234. </div>
  235. </div>
  236. </div>
  237. <div class="footer">
  238. <hr>Generated by GTK-Doc V1.33.1</div>
  239. </body>
  240. </html>