📄 glib-threads.html
字号:
If <em class="parameter"><code>joinable</code></em> is <code class="literal">TRUE</code>, you can wait for this threads terminationcalling <a href="glib-Threads.html#g-thread-join"><code class="function">g_thread_join()</code></a>. Otherwise the thread will just disappear, whenready. </p><p>The new thread executes the function <em class="parameter"><code>func</code></em> with the argument<em class="parameter"><code>data</code></em>. If the thread was created successfully, it is returned.</p><p><em class="parameter"><code>error</code></em> can be <code class="literal">NULL</code> to ignore errors, or non-<code class="literal">NULL</code> to report errors. Theerror is set, if and only if the function returns <code class="literal">NULL</code>.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>func</code></em> :</span></td><td>a function to execute in the new thread.</td></tr><tr><td><span class="term"><em class="parameter"><code>data</code></em> :</span></td><td>an argument to supply to the new thread.</td></tr><tr><td><span class="term"><em class="parameter"><code>joinable</code></em> :</span></td><td>should this thread be joinable?</td></tr><tr><td><span class="term"><em class="parameter"><code>error</code></em> :</span></td><td>return location for error.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the new <a href="glib-Threads.html#GThread"><span class="type">GThread</span></a> on success.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2871791"></a><h3><a name="g-thread-create-full"></a>g_thread_create_full ()</h3><a class="indexterm" name="id2871802"></a><pre class="programlisting"><a href="glib-Threads.html#GThread">GThread</a>* g_thread_create_full (<a href="glib-Threads.html#GThreadFunc">GThreadFunc</a> func, <a href="glib-Basic-Types.html#gpointer">gpointer</a> data, <a href="glib-Basic-Types.html#gulong">gulong</a> stack_size, <a href="glib-Basic-Types.html#gboolean">gboolean</a> joinable, <a href="glib-Basic-Types.html#gboolean">gboolean</a> bound, <a href="glib-Threads.html#GThreadPriority">GThreadPriority</a> priority, <a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>This function creates a new thread with the priority <em class="parameter"><code>priority</code></em>. If theunderlying thread implementation supports it, the thread gets a stack size of <em class="parameter"><code>stack_size</code></em> or the default value for the current platform, if <em class="parameter"><code>stack_size</code></em> is 0.</p><p>If <em class="parameter"><code>joinable</code></em> is <code class="literal">TRUE</code>, you can wait for this threads terminationcalling <a href="glib-Threads.html#g-thread-join"><code class="function">g_thread_join()</code></a>. Otherwise the thread will just disappear, whenready. If <em class="parameter"><code>bound</code></em> is <code class="literal">TRUE</code>, this thread will be scheduled in the systemscope, otherwise the implementation is free to do scheduling in theprocess scope. The first variant is more expensive resource-wise, butgenerally faster. On some systems (e.g. Linux) all threads are bound.</p><p>The new thread executes the function <em class="parameter"><code>func</code></em> with the argument<em class="parameter"><code>data</code></em>. If the thread was created successfully, it is returned.</p><p><em class="parameter"><code>error</code></em> can be <code class="literal">NULL</code> to ignore errors, or non-<code class="literal">NULL</code> to report errors. Theerror is set, if and only if the function returns <code class="literal">NULL</code>.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>It is not guaranteed, that threads with different priorities reallybehave accordingly. On some systems (e.g. Linux) there are no threadpriorities. On other systems (e.g. Solaris) there doesn't seem to bedifferent scheduling for different priorities. All in all try to avoidbeing dependent on priorities. Use <code class="literal">G_THREAD_PRIORITY_NORMAL</code> here as adefault.</p></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Only use <a href="glib-Threads.html#g-thread-create-full"><code class="function">g_thread_create_full()</code></a>, when you really can't use<a href="glib-Threads.html#g-thread-create"><code class="function">g_thread_create()</code></a> instead. <a href="glib-Threads.html#g-thread-create"><code class="function">g_thread_create()</code></a> does not take<em class="parameter"><code>stack_size</code></em>, <em class="parameter"><code>bound</code></em> and <em class="parameter"><code>priority</code></em> as arguments, as they should only beused for cases, where it is inevitable. </p></div><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>func</code></em> :</span></td><td>a function to execute in the new thread.</td></tr><tr><td><span class="term"><em class="parameter"><code>data</code></em> :</span></td><td>an argument to supply to the new thread.</td></tr><tr><td><span class="term"><em class="parameter"><code>stack_size</code></em> :</span></td><td>a stack size for the new thread.</td></tr><tr><td><span class="term"><em class="parameter"><code>joinable</code></em> :</span></td><td>should this thread be joinable?</td></tr><tr><td><span class="term"><em class="parameter"><code>bound</code></em> :</span></td><td>should this thread be bound to a system thread?</td></tr><tr><td><span class="term"><em class="parameter"><code>priority</code></em> :</span></td><td>a priority for the thread.</td></tr><tr><td><span class="term"><em class="parameter"><code>error</code></em> :</span></td><td>return location for error.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the new <a href="glib-Threads.html#GThread"><span class="type">GThread</span></a> on success.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2872186"></a><h3><a name="g-thread-self"></a>g_thread_self ()</h3><a class="indexterm" name="id2872196"></a><pre class="programlisting"><a href="glib-Threads.html#GThread">GThread</a>* g_thread_self (void);</pre><p>This functions returns the <a href="glib-Threads.html#GThread"><span class="type">GThread</span></a> corresponding to the calling thread.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the current thread.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2872242"></a><h3><a name="g-thread-join"></a>g_thread_join ()</h3><a class="indexterm" name="id2872253"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gpointer">gpointer</a> g_thread_join (<a href="glib-Threads.html#GThread">GThread</a> *thread);</pre><p>Waits until <em class="parameter"><code>thread</code></em> finishes, i.e. the function <em class="parameter"><code>func</code></em>, as givento <a href="glib-Threads.html#g-thread-create"><code class="function">g_thread_create()</code></a>, returns or <a href="glib-Threads.html#g-thread-exit"><code class="function">g_thread_exit()</code></a> is called by<em class="parameter"><code>thread</code></em>. All resources of <em class="parameter"><code>thread</code></em> including the <a href="glib-Threads.html#GThread"><span class="type">GThread</span></a> struct arereleased. <em class="parameter"><code>thread</code></em> must have been created with <em class="parameter"><code>joinable</code></em>=<code class="literal">TRUE</code> in<a href="glib-Threads.html#g-thread-create"><code class="function">g_thread_create()</code></a>. The value returned by <em class="parameter"><code>func</code></em> or given to<a href="glib-Threads.html#g-thread-exit"><code class="function">g_thread_exit()</code></a> by <em class="parameter"><code>thread</code></em> is returned by this function.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>thread</code></em> :</span></td><td>a <a href="glib-Threads.html#GThread"><span class="type">GThread</span></a> to be waited for.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the return value of the thread.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2872425"></a><h3><a name="g-thread-set-priority"></a>g_thread_set_priority ()</h3><a class="indexterm" name="id2872436"></a><pre class="programlisting">void g_thread_set_priority (<a href="glib-Threads.html#GThread">GThread</a> *thread, <a href="glib-Threads.html#GThreadPriority">GThreadPriority</a> priority);</pre><p>Changes the priority of <em class="parameter"><code>thread</code></em> to <em class="parameter"><code>priority</code></em>.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>It is not guaranteed, that threads with different priorities reallybehave accordingly. On some systems (e.g. Linux) there are no threadpriorities. On other systems (e.g. Solaris) there doesn't seem to bedifferent scheduling for different priorities. All in all try to avoidbeing dependent on priorities.</p></div><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>thread</code></em> :</span></td><td>a <a href="glib-Threads.html#GThread"><span class="type">GThread</span></a>.</td></tr><tr><td><span class="term"><em class="parameter"><code>priority</code></em> :</span></td><td>a new priority for <em class="parameter"><code>thread</code></em>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2872542"></a><h3><a name="g-thread-yield"></a>g_thread_yield ()</h3><a class="indexterm" name="id2872552"></a><pre class="programlisting">void g_thread_yield ();</pre><p>Gives way to other threads waiting to be scheduled. </p><p>This function is often used as a method to make busy wait lessevil. But in most cases, you will encounter, there are better methodsto do that. So in general you shouldn't use that function.</p></div><hr><div class="refsect2" lang="en"><a name="id2872580"></a><h3><a name="g-thread-exit"></a>g_thread_exit ()</h3><a class="indexterm" name="id2872591"></a><pre class="programlisting">void g_thread_exit (<a href="glib-Basic-Types.html#gpointer">gpointer</a> retval);</pre>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -