📄 glib-thread-pools.html
字号:
<a class="indexterm" name="id2891053"></a><pre class="programlisting">void g_thread_pool_set_max_threads (<a href="glib-Thread-Pools.html#GThreadPool">GThreadPool</a> *pool, <a href="glib-Basic-Types.html#gint">gint</a> max_threads, <a 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 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 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 <code class="literal">NULL</code> to ignore errors, or non-<code class="literal">NULL</code> 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><span class="term"><em class="parameter"><code>pool</code></em> :</span></td><td> a <a href="glib-Thread-Pools.html#GThreadPool"><span class="type">GThreadPool</span></a></td></tr><tr><td><span class="term"><em class="parameter"><code>max_threads</code></em> :</span></td><td> a new maximal number of threads for <em class="parameter"><code>pool</code></em></td></tr><tr><td><span class="term"><em class="parameter"><code>error</code></em> :</span></td><td> return location for error</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2891254"></a><h3><a name="g-thread-pool-get-max-threads"></a>g_thread_pool_get_max_threads ()</h3><a class="indexterm" name="id2891264"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gint">gint</a> g_thread_pool_get_max_threads (<a 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><span class="term"><em class="parameter"><code>pool</code></em> :</span></td><td> a <a href="glib-Thread-Pools.html#GThreadPool"><span class="type">GThreadPool</span></a></td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> the maximal number of threads</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2891339"></a><h3><a name="g-thread-pool-get-num-threads"></a>g_thread_pool_get_num_threads ()</h3><a class="indexterm" name="id2891350"></a><pre class="programlisting"><a href="glib-Basic-Types.html#guint">guint</a> g_thread_pool_get_num_threads (<a 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><span class="term"><em class="parameter"><code>pool</code></em> :</span></td><td> a <a href="glib-Thread-Pools.html#GThreadPool"><span class="type">GThreadPool</span></a></td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> the number of threads currently running</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2891425"></a><h3><a name="g-thread-pool-unprocessed"></a>g_thread_pool_unprocessed ()</h3><a class="indexterm" name="id2891436"></a><pre class="programlisting"><a href="glib-Basic-Types.html#guint">guint</a> g_thread_pool_unprocessed (<a 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><span class="term"><em class="parameter"><code>pool</code></em> :</span></td><td> a <a href="glib-Thread-Pools.html#GThreadPool"><span class="type">GThreadPool</span></a></td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> the number of unprocessed tasks</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2891510"></a><h3><a name="g-thread-pool-free"></a>g_thread_pool_free ()</h3><a class="indexterm" name="id2891521"></a><pre class="programlisting">void g_thread_pool_free (<a href="glib-Thread-Pools.html#GThreadPool">GThreadPool</a> *pool, <a href="glib-Basic-Types.html#gboolean">gboolean</a> immediate, <a 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 <code class="literal">TRUE</code>, 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 <code class="literal">TRUE</code>, 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><span class="term"><em class="parameter"><code>pool</code></em> :</span></td><td> a <a href="glib-Thread-Pools.html#GThreadPool"><span class="type">GThreadPool</span></a></td></tr><tr><td><span class="term"><em class="parameter"><code>immediate</code></em> :</span></td><td> should <em class="parameter"><code>pool</code></em> shut down immediately?</td></tr><tr><td><span class="term"><em class="parameter"><code>wait</code></em> :</span></td><td> should the function wait for all tasks to be finished?</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2891705"></a><h3><a name="g-thread-pool-set-max-unused-threads"></a>g_thread_pool_set_max_unused_threads ()</h3><a class="indexterm" name="id2891717"></a><pre class="programlisting">void g_thread_pool_set_max_unused_threads (<a href="glib-Basic-Types.html#gint">gint</a> max_threads);</pre><p>Sets the maximal number of unused threads to <em class="parameter"><code>max_threads</code></em>. If<em class="parameter"><code>max_threads</code></em> is -1, no limit is imposed on the number of unusedthreads.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>max_threads</code></em> :</span></td><td> maximal number of unused threads</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2891782"></a><h3><a name="g-thread-pool-get-max-unused-threads"></a>g_thread_pool_get_max_unused_threads ()</h3><a class="indexterm" name="id2891794"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gint">gint</a> g_thread_pool_get_max_unused_threads (void);</pre><p>Returns the maximal allowed number of unused threads.</p><p></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 maximal number of unused threads</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2891836"></a><h3><a name="g-thread-pool-get-num-unused-threads"></a>g_thread_pool_get_num_unused_threads ()</h3><a class="indexterm" name="id2891847"></a><pre class="programlisting"><a href="glib-Basic-Types.html#guint">guint</a> g_thread_pool_get_num_unused_threads (void);</pre><p>Returns the number of currently unused threads.</p><p></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 number of currently unused threads</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2891889"></a><h3><a name="g-thread-pool-stop-unused-threads"></a>g_thread_pool_stop_unused_threads ()</h3><a class="indexterm" name="id2891902"></a><pre class="programlisting">void g_thread_pool_stop_unused_threads (void);</pre><p>Stops all currently unused threads. This does not change themaximal number of unused threads. This function can be used toregularly stop all unused threads e.g. from <a href="glib-The-Main-Event-Loop.html#g-timeout-add"><code class="function">g_timeout_add()</code></a>.</p><p></p></div></div><div class="refsect1" lang="en"><a name="id2891941"></a><h2>See Also</h2><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><a href="glib-Threads.html#GThread"><span class="type">GThread</span></a></span></td><td><p>GLib thread system.</p></td></tr></tbody></table></div><p></p></div></div><table class="navigation" width="100%" summary="Navigation footer" cellpadding="2" cellspacing="0"><tr valign="middle"><td align="left"><a accesskey="p" href="glib-Threads.html"><b><< Threads</b></a></td><td align="right"><a accesskey="n" href="glib-Asynchronous-Queues.html"><b>Asynchronous Queues >></b></a></td></tr></table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -