📄 glib-thread-pools.html
字号:
</td></tr><tr><td><p><span class="term"><em class="parameter"><code>exclusive</code></em> :</span></p></td><td> should this thread pool be exclusive?</td></tr><tr><td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td><td> return location for error</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> the new <a class="link" href="glib-Thread-Pools.html#GThreadPool"><span class="type">GThreadPool</span></a></td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2905566"></a><h3><a name="g-thread-pool-push"></a>g_thread_pool_push ()</h3><a class="indexterm" name="id2905579"></a><pre class="programlisting">void g_thread_pool_push (<a class="link" href="glib-Thread-Pools.html#GThreadPool">GThreadPool</a> *pool, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> data, <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>Inserts <em class="parameter"><code>data</code></em> into the list of tasks to be executed by <em class="parameter"><code>pool</code></em>. Whenthe number of currently running threads is lower than the maximalallowed number of threads, a new thread is started (or reused) withthe properties given to <a class="link" href="glib-Thread-Pools.html#g-thread-pool-new"><code class="function">g_thread_pool_new()</code></a>. Otherwise <em class="parameter"><code>data</code></em> staysin the queue until a thread in this pool finishes its previous taskand processes <em class="parameter"><code>data</code></em>. </p><p><em class="parameter"><code>error</code></em> can be <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore errors, or non-<a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to reporterrors. An error can only occur when a new thread couldn't becreated. In that case <em class="parameter"><code>data</code></em> is simply appended to the queue of workto do.</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>pool</code></em> :</span></p></td><td> a <a class="link" href="glib-Thread-Pools.html#GThreadPool"><span class="type">GThreadPool</span></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>data</code></em> :</span></p></td><td> a new task for <em class="parameter"><code>pool</code></em></td></tr><tr><td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td><td> return location for error</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2905763"></a><h3><a name="g-thread-pool-set-max-threads"></a>g_thread_pool_set_max_threads ()</h3><a class="indexterm" name="id2905777"></a><pre class="programlisting">void g_thread_pool_set_max_threads (<a class="link" href="glib-Thread-Pools.html#GThreadPool">GThreadPool</a> *pool, <a class="link" href="glib-Basic-Types.html#gint">gint</a> max_threads, <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>Sets the maximal allowed number of threads for <em class="parameter"><code>pool</code></em>. A value of -1means, that the maximal number of threads is unlimited.</p><p>Setting <em class="parameter"><code>max_threads</code></em> to 0 means stopping all work for <em class="parameter"><code>pool</code></em>. It iseffectively frozen until <em class="parameter"><code>max_threads</code></em> is set to a non-zero valueagain.</p><p>A thread is never terminated while calling <em class="parameter"><code>func</code></em>, as supplied by<a class="link" href="glib-Thread-Pools.html#g-thread-pool-new"><code class="function">g_thread_pool_new()</code></a>. Instead the maximal number of threads onlyhas effect for the allocation of new threads in <a class="link" href="glib-Thread-Pools.html#g-thread-pool-push"><code class="function">g_thread_pool_push()</code></a>. A new thread is allocated, whenever the number of currentlyrunning threads in <em class="parameter"><code>pool</code></em> is smaller than the maximal number.</p><p><em class="parameter"><code>error</code></em> can be <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore errors, or non-<a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to reporterrors. An error can only occur when a new thread couldn't becreated.</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>pool</code></em> :</span></p></td><td> a <a class="link" href="glib-Thread-Pools.html#GThreadPool"><span class="type">GThreadPool</span></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>max_threads</code></em> :</span></p></td><td> a new maximal number of threads for <em class="parameter"><code>pool</code></em></td></tr><tr><td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td><td> return location for error</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2905987"></a><h3><a name="g-thread-pool-get-max-threads"></a>g_thread_pool_get_max_threads ()</h3><a class="indexterm" name="id2906000"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gint">gint</a> g_thread_pool_get_max_threads (<a class="link" href="glib-Thread-Pools.html#GThreadPool">GThreadPool</a> *pool);</pre><p>Returns the maximal number of threads for <em class="parameter"><code>pool</code></em>.</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>pool</code></em> :</span></p></td><td> a <a class="link" href="glib-Thread-Pools.html#GThreadPool"><span class="type">GThreadPool</span></a></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> the maximal number of threads</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2906074"></a><h3><a name="g-thread-pool-get-num-threads"></a>g_thread_pool_get_num_threads ()</h3><a class="indexterm" name="id2906088"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#guint">guint</a> g_thread_pool_get_num_threads (<a class="link" href="glib-Thread-Pools.html#GThreadPool">GThreadPool</a> *pool);</pre><p>Returns the number of threads currently running in <em class="parameter"><code>pool</code></em>.</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>pool</code></em> :</span></p></td><td> a <a class="link" href="glib-Thread-Pools.html#GThreadPool"><span class="type">GThreadPool</span></a></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> the number of threads currently running</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2906163"></a><h3><a name="g-thread-pool-unprocessed"></a>g_thread_pool_unprocessed ()</h3><a class="indexterm" name="id2906176"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#guint">guint</a> g_thread_pool_unprocessed (<a class="link" href="glib-Thread-Pools.html#GThreadPool">GThreadPool</a> *pool);</pre><p>Returns the number of tasks still unprocessed in <em class="parameter"><code>pool</code></em>.</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>pool</code></em> :</span></p></td><td> a <a class="link" href="glib-Thread-Pools.html#GThreadPool"><span class="type">GThreadPool</span></a></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> the number of unprocessed tasks</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2906250"></a><h3><a name="g-thread-pool-free"></a>g_thread_pool_free ()</h3><a class="indexterm" name="id2906264"></a><pre class="programlisting">void g_thread_pool_free (<a class="link" href="glib-Thread-Pools.html#GThreadPool">GThreadPool</a> *pool, <a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> immediate, <a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> wait_);</pre><p>Frees all resources allocated for <em class="parameter"><code>pool</code></em>.</p><p>If <em class="parameter"><code>immediate</code></em> is <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>, no new task is processed for<em class="parameter"><code>pool</code></em>. Otherwise <em class="parameter"><code>pool</code></em> is not freed before the last task isprocessed. Note however, that no thread of this pool isinterrupted, while processing a task. Instead at least all stillrunning threads can finish their tasks before the <em class="parameter"><code>pool</code></em> is freed.</p><p>If <em class="parameter"><code>wait_</code></em> is <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>, the functions does not return before all tasksto be processed (dependent on <em class="parameter"><code>immediate</code></em>, whether all or only thecurrently running) are ready. Otherwise the function returns immediately.</p><p>After calling this function <em class="parameter"><code>pool</code></em> must not be used anymore.</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>pool</code></em> :</span></p></td>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -