⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glib-threads.html

📁 最新gtk中文资料集
💻 HTML
📖 第 1 页 / 共 5 页
字号:
</td></tr><tr><td><p><span class="term"><em class="parameter"><code>priority</code></em>&#160;:</span></p></td><td>a priority for the thread.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>error</code></em>&#160;:</span></p></td><td>return location for error.</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td><td>the new <a class="link" 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="id2884591"></a><h3><a name="g-thread-self"></a>g_thread_self ()</h3><a class="indexterm" name="id2884604"></a><pre class="programlisting"><a class="link" href="glib-Threads.html#GThread">GThread</a>*            g_thread_self                       (void);</pre><p>This functions returns the <a class="link" 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><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td><td>the current thread.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2884650"></a><h3><a name="g-thread-join"></a>g_thread_join ()</h3><a class="indexterm" name="id2884662"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a>            g_thread_join                       (<a class="link" 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 class="link" href="glib-Threads.html#g-thread-create"><code class="function">g_thread_create()</code></a>, returns or <a class="link" 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 class="link" 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>=<a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> in<a class="link" 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 class="link" 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><p><span class="term"><em class="parameter"><code>thread</code></em>&#160;:</span></p></td><td>a <a class="link" href="glib-Threads.html#GThread"><span class="type">GThread</span></a> to be waited for.</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td><td>the return value of the thread.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2884839"></a><h3><a name="g-thread-set-priority"></a>g_thread_set_priority ()</h3><a class="indexterm" name="id2884852"></a><pre class="programlisting">void                g_thread_set_priority               (<a class="link" href="glib-Threads.html#GThread">GThread</a> *thread,                                                         <a class="link" 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><p><span class="term"><em class="parameter"><code>thread</code></em>&#160;:</span></p></td><td>a <a class="link" href="glib-Threads.html#GThread"><span class="type">GThread</span></a>.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>priority</code></em>&#160;:</span></p></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="id2884958"></a><h3><a name="g-thread-yield"></a>g_thread_yield ()</h3><a class="indexterm" name="id2884971"></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 this function.</p></div><hr><div class="refsect2" lang="en"><a name="id2885000"></a><h3><a name="g-thread-exit"></a>g_thread_exit ()</h3><a class="indexterm" name="id2885013"></a><pre class="programlisting">void                g_thread_exit                       (<a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> retval);</pre><p>Exits the current thread. If another thread is waiting for that threadusing <a class="link" href="glib-Threads.html#g-thread-join"><code class="function">g_thread_join()</code></a> and the current thread is joinable, the waitingthread will be woken up and get <em class="parameter"><code>retval</code></em> as the return value of<a class="link" href="glib-Threads.html#g-thread-join"><code class="function">g_thread_join()</code></a>. If the current thread is not joinable, <em class="parameter"><code>retval</code></em> isignored. Calling</p><p></p><div class="informalexample"><pre class="programlisting">g_thread_exit (retval);</pre></div><p></p><p>is equivalent to calling </p><p></p><div class="informalexample"><pre class="programlisting">return retval;</pre></div><p></p><p>in the function <em class="parameter"><code>func</code></em>, as given to <a class="link" href="glib-Threads.html#g-thread-create"><code class="function">g_thread_create()</code></a>.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Never call <a class="link" href="glib-Threads.html#g-thread-exit"><code class="function">g_thread_exit()</code></a> from within a thread of a <a class="link" href="glib-Thread-Pools.html#GThreadPool"><span class="type">GThreadPool</span></a>, asthat will mess up the bookkeeping and lead to funny and unwanted results.</p></div><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>retval</code></em>&#160;:</span></p></td><td>the return value of this thread.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2885174"></a><h3><a name="g-thread-foreach"></a>g_thread_foreach ()</h3><a class="indexterm" name="id2885190"></a><pre class="programlisting">void                g_thread_foreach                    (<a class="link" href="glib-Doubly-Linked-Lists.html#GFunc">GFunc</a> thread_func,                                                         <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);</pre><p>Call <em class="parameter"><code>thread_func</code></em> on all existing <a class="link" href="glib-Threads.html#GThread"><span class="type">GThread</span></a> structures. Note thatthreads may decide to exit while <em class="parameter"><code>thread_func</code></em> is running, sowithout intimate knowledge about the lifetime of foreign threads,<em class="parameter"><code>thread_func</code></em> shouldn't access the GThread* pointer passed in asfirst argument. However, <em class="parameter"><code>thread_func</code></em> will not be called for threadswhich are known to have exited already.</p><p>Due to thread lifetime checks, this function has an execution complexitywhich is quadratic in the number of existing threads.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>thread_func</code></em>&#160;:</span></p></td><td> function to call for all GThread structures</td></tr><tr><td><p><span class="term"><em class="parameter"><code>user_data</code></em>&#160;:</span></p></td><td>   second argument to <em class="parameter"><code>thread_func</code></em></td></tr></tbody></table></div><p class="since">Since  2.10</p></div><hr><div class="refsect2" lang="en"><a name="id2885317"></a><h3><a name="GMutex"></a>GMutex</h3><a class="indexterm" name="id2885329"></a><pre class="programlisting">typedef struct _GMutex GMutex;</pre><p>The <a class="link" href="glib-Threads.html#GMutex"><span class="type">GMutex</span></a> struct is an opaque data structure to represent a mutex(mutual exclusion). It can be used to protect data against sharedaccess. Take for example the following function:</p><div class="example"><a name="id2885355"></a><p class="title"><b>Example&#160;2.&#160;A function which will not work in a threaded environment</b></p><div class="example-contents"><pre class="programlisting">  int give_me_next_number ()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -