2
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
4
<!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
5
<!ENTITY version SYSTEM "version.xml">
7
<refentry id="glib-Thread-Pools">
9
<refentrytitle role="top_of_page" id="glib-Thread-Pools.top_of_page">Thread Pools</refentrytitle>
10
<manvolnum>3</manvolnum>
11
<refmiscinfo>GLIB Library</refmiscinfo>
15
<refname>Thread Pools</refname>
16
<refpurpose>pools of threads to execute work concurrently</refpurpose>
19
<refsynopsisdiv id="glib-Thread-Pools.synopsis" role="synopsis">
20
<title role="synopsis.title">Synopsis</title>
24
#include <glib.h>
26
<link linkend="GThreadPool">GThreadPool</link>;
27
<link linkend="GThreadPool">GThreadPool</link>* <link linkend="g-thread-pool-new">g_thread_pool_new</link> (<link linkend="GFunc">GFunc</link> func,
28
<link linkend="gpointer">gpointer</link> user_data,
29
<link linkend="gint">gint</link> max_threads,
30
<link linkend="gboolean">gboolean</link> exclusive,
31
<link linkend="GError">GError</link> **error);
32
<link linkend="void">void</link> <link linkend="g-thread-pool-push">g_thread_pool_push</link> (<link linkend="GThreadPool">GThreadPool</link> *pool,
33
<link linkend="gpointer">gpointer</link> data,
34
<link linkend="GError">GError</link> **error);
35
<link linkend="void">void</link> <link linkend="g-thread-pool-set-max-threads">g_thread_pool_set_max_threads</link> (<link linkend="GThreadPool">GThreadPool</link> *pool,
36
<link linkend="gint">gint</link> max_threads,
37
<link linkend="GError">GError</link> **error);
38
<link linkend="gint">gint</link> <link linkend="g-thread-pool-get-max-threads">g_thread_pool_get_max_threads</link> (<link linkend="GThreadPool">GThreadPool</link> *pool);
39
<link linkend="guint">guint</link> <link linkend="g-thread-pool-get-num-threads">g_thread_pool_get_num_threads</link> (<link linkend="GThreadPool">GThreadPool</link> *pool);
40
<link linkend="guint">guint</link> <link linkend="g-thread-pool-unprocessed">g_thread_pool_unprocessed</link> (<link linkend="GThreadPool">GThreadPool</link> *pool);
41
<link linkend="void">void</link> <link linkend="g-thread-pool-free">g_thread_pool_free</link> (<link linkend="GThreadPool">GThreadPool</link> *pool,
42
<link linkend="gboolean">gboolean</link> immediate,
43
<link linkend="gboolean">gboolean</link> wait_);
44
<link linkend="void">void</link> <link linkend="g-thread-pool-set-max-unused-threads">g_thread_pool_set_max_unused_threads</link>
45
(<link linkend="gint">gint</link> max_threads);
46
<link linkend="gint">gint</link> <link linkend="g-thread-pool-get-max-unused-threads">g_thread_pool_get_max_unused_threads</link>
48
<link linkend="guint">guint</link> <link linkend="g-thread-pool-get-num-unused-threads">g_thread_pool_get_num_unused_threads</link>
50
<link linkend="void">void</link> <link linkend="g-thread-pool-stop-unused-threads">g_thread_pool_stop_unused_threads</link> (void);
51
<link linkend="void">void</link> <link linkend="g-thread-pool-set-sort-function">g_thread_pool_set_sort_function</link> (<link linkend="GThreadPool">GThreadPool</link> *pool,
52
<link linkend="GCompareDataFunc">GCompareDataFunc</link> func,
53
<link linkend="gpointer">gpointer</link> user_data);
54
<link linkend="void">void</link> <link linkend="g-thread-pool-set-max-idle-time">g_thread_pool_set_max_idle_time</link> (<link linkend="guint">guint</link> interval);
55
<link linkend="guint">guint</link> <link linkend="g-thread-pool-get-max-idle-time">g_thread_pool_get_max_idle_time</link> (void);
67
<refsect1 id="glib-Thread-Pools.description" role="desc">
68
<title role="desc.title">Description</title>
70
Sometimes you wish to asynchronously fork out the execution of work
71
and continue working in your own thread. If that will happen often,
72
the overhead of starting and destroying a thread each time might be
73
too high. In such cases reusing already started threads seems like a
74
good idea. And it indeed is, but implementing this can be tedious
78
Therefore GLib provides thread pools for your convenience. An added
79
advantage is, that the threads can be shared between the different
80
subsystems of your program, when they are using GLib.
83
To create a new thread pool, you use <link linkend="g-thread-pool-new"><function>g_thread_pool_new()</function></link>. It is
84
destroyed by <link linkend="g-thread-pool-free"><function>g_thread_pool_free()</function></link>.
87
If you want to execute a certain task within a thread pool, you call
88
<link linkend="g-thread-pool-push"><function>g_thread_pool_push()</function></link>.
91
To get the current number of running threads you call
92
<link linkend="g-thread-pool-get-num-threads"><function>g_thread_pool_get_num_threads()</function></link>. To get the number of still
93
unprocessed tasks you call <link linkend="g-thread-pool-unprocessed"><function>g_thread_pool_unprocessed()</function></link>. To control
94
the maximal number of threads for a thread pool, you use
95
<link linkend="g-thread-pool-get-max-threads"><function>g_thread_pool_get_max_threads()</function></link> and <link linkend="g-thread-pool-set-max-threads"><function>g_thread_pool_set_max_threads()</function></link>.
98
Finally you can control the number of unused threads, that are kept
99
alive by GLib for future use. The current number can be fetched with
100
<link linkend="g-thread-pool-get-num-unused-threads"><function>g_thread_pool_get_num_unused_threads()</function></link>. The maximal number can be
101
controlled by <link linkend="g-thread-pool-get-max-unused-threads"><function>g_thread_pool_get_max_unused_threads()</function></link> and
102
<link linkend="g-thread-pool-set-max-unused-threads"><function>g_thread_pool_set_max_unused_threads()</function></link>. All currently unused threads
103
can be stopped by calling <link linkend="g-thread-pool-stop-unused-threads"><function>g_thread_pool_stop_unused_threads()</function></link>.</para>
108
<refsect1 id="glib-Thread-Pools.details" role="details">
109
<title role="details.title">Details</title>
110
<refsect2 id="GThreadPool" role="struct">
111
<title>GThreadPool</title>
112
<indexterm zone="GThreadPool"><primary sortas="ThreadPool">GThreadPool</primary></indexterm><programlisting>typedef struct {
119
The <link linkend="GThreadPool"><type>GThreadPool</type></link> struct represents a thread pool. It has three
120
public read-only members, but the underlying struct is bigger, so
121
you must not copy this struct.</para>
123
</para><variablelist role="struct">
125
<term><link linkend="GFunc">GFunc</link> <structfield>func</structfield>;</term>
126
<listitem><simpara> the function to execute in the threads of this pool
127
</simpara></listitem>
130
<term><link linkend="gpointer">gpointer</link> <structfield>user_data</structfield>;</term>
131
<listitem><simpara> the user data for the threads of this pool
132
</simpara></listitem>
135
<term><link linkend="gboolean">gboolean</link> <structfield>exclusive</structfield>;</term>
136
<listitem><simpara> are all threads exclusive to this pool
137
</simpara></listitem>
139
</variablelist></refsect2>
140
<refsect2 id="g-thread-pool-new" role="function">
141
<title>g_thread_pool_new ()</title>
142
<indexterm zone="g-thread-pool-new"><primary sortas="thread_pool_new">g_thread_pool_new</primary></indexterm><programlisting><link linkend="GThreadPool">GThreadPool</link>* g_thread_pool_new (<link linkend="GFunc">GFunc</link> func,
143
<link linkend="gpointer">gpointer</link> user_data,
144
<link linkend="gint">gint</link> max_threads,
145
<link linkend="gboolean">gboolean</link> exclusive,
146
<link linkend="GError">GError</link> **error);</programlisting>
148
This function creates a new thread pool.
151
Whenever you call <link linkend="g-thread-pool-push"><function>g_thread_pool_push()</function></link>, either a new thread is
152
created or an unused one is reused. At most <parameter>max_threads</parameter> threads
153
are running concurrently for this thread pool. <parameter>max_threads</parameter> = -1
154
allows unlimited threads to be created for this thread pool. The
155
newly created or reused thread now executes the function <parameter>func</parameter> with
156
the two arguments. The first one is the parameter to
157
<link linkend="g-thread-pool-push"><function>g_thread_pool_push()</function></link> and the second one is <parameter>user_data</parameter>.
160
The parameter <parameter>exclusive</parameter> determines, whether the thread pool owns
161
all threads exclusive or whether the threads are shared
162
globally. If <parameter>exclusive</parameter> is <link linkend="TRUE--CAPS"><literal>TRUE</literal></link>, <parameter>max_threads</parameter> threads are started
163
immediately and they will run exclusively for this thread pool until
164
it is destroyed by <link linkend="g-thread-pool-free"><function>g_thread_pool_free()</function></link>. If <parameter>exclusive</parameter> is <link linkend="FALSE--CAPS"><literal>FALSE</literal></link>,
165
threads are created, when needed and shared between all
166
non-exclusive thread pools. This implies that <parameter>max_threads</parameter> may not
167
be -1 for exclusive thread pools.
170
<parameter>error</parameter> can be <link linkend="NULL--CAPS"><literal>NULL</literal></link> to ignore errors, or non-<link linkend="NULL--CAPS"><literal>NULL</literal></link> to report
171
errors. An error can only occur when <parameter>exclusive</parameter> is set to <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> and
172
not all <parameter>max_threads</parameter> threads could be created.</para>
174
</para><variablelist role="params">
175
<varlistentry><term><parameter>func</parameter> :</term>
176
<listitem><simpara> a function to execute in the threads of the new thread pool
177
</simpara></listitem></varlistentry>
178
<varlistentry><term><parameter>user_data</parameter> :</term>
179
<listitem><simpara> user data that is handed over to <parameter>func</parameter> every time it
181
</simpara></listitem></varlistentry>
182
<varlistentry><term><parameter>max_threads</parameter> :</term>
183
<listitem><simpara> the maximal number of threads to execute concurrently in
184
the new thread pool, -1 means no limit
185
</simpara></listitem></varlistentry>
186
<varlistentry><term><parameter>exclusive</parameter> :</term>
187
<listitem><simpara> should this thread pool be exclusive?
188
</simpara></listitem></varlistentry>
189
<varlistentry><term><parameter>error</parameter> :</term>
190
<listitem><simpara> return location for error
191
</simpara></listitem></varlistentry>
192
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> the new <link linkend="GThreadPool"><type>GThreadPool</type></link>
193
</simpara></listitem></varlistentry>
194
</variablelist></refsect2>
195
<refsect2 id="g-thread-pool-push" role="function">
196
<title>g_thread_pool_push ()</title>
197
<indexterm zone="g-thread-pool-push"><primary sortas="thread_pool_push">g_thread_pool_push</primary></indexterm><programlisting><link linkend="void">void</link> g_thread_pool_push (<link linkend="GThreadPool">GThreadPool</link> *pool,
198
<link linkend="gpointer">gpointer</link> data,
199
<link linkend="GError">GError</link> **error);</programlisting>
201
Inserts <parameter>data</parameter> into the list of tasks to be executed by <parameter>pool</parameter>. When
202
the number of currently running threads is lower than the maximal
203
allowed number of threads, a new thread is started (or reused) with
204
the properties given to <link linkend="g-thread-pool-new"><function>g_thread_pool_new()</function></link>. Otherwise <parameter>data</parameter> stays
205
in the queue until a thread in this pool finishes its previous task
206
and processes <parameter>data</parameter>.
209
<parameter>error</parameter> can be <link linkend="NULL--CAPS"><literal>NULL</literal></link> to ignore errors, or non-<link linkend="NULL--CAPS"><literal>NULL</literal></link> to report
210
errors. An error can only occur when a new thread couldn't be
211
created. In that case <parameter>data</parameter> is simply appended to the queue of work
214
</para><variablelist role="params">
215
<varlistentry><term><parameter>pool</parameter> :</term>
216
<listitem><simpara> a <link linkend="GThreadPool"><type>GThreadPool</type></link>
217
</simpara></listitem></varlistentry>
218
<varlistentry><term><parameter>data</parameter> :</term>
219
<listitem><simpara> a new task for <parameter>pool</parameter>
220
</simpara></listitem></varlistentry>
221
<varlistentry><term><parameter>error</parameter> :</term>
222
<listitem><simpara> return location for error
223
</simpara></listitem></varlistentry>
224
</variablelist></refsect2>
225
<refsect2 id="g-thread-pool-set-max-threads" role="function">
226
<title>g_thread_pool_set_max_threads ()</title>
227
<indexterm zone="g-thread-pool-set-max-threads"><primary sortas="thread_pool_set_max_threads">g_thread_pool_set_max_threads</primary></indexterm><programlisting><link linkend="void">void</link> g_thread_pool_set_max_threads (<link linkend="GThreadPool">GThreadPool</link> *pool,
228
<link linkend="gint">gint</link> max_threads,
229
<link linkend="GError">GError</link> **error);</programlisting>
231
Sets the maximal allowed number of threads for <parameter>pool</parameter>. A value of -1
232
means, that the maximal number of threads is unlimited.
235
Setting <parameter>max_threads</parameter> to 0 means stopping all work for <parameter>pool</parameter>. It is
236
effectively frozen until <parameter>max_threads</parameter> is set to a non-zero value
240
A thread is never terminated while calling <parameter>func</parameter>, as supplied by
241
<link linkend="g-thread-pool-new"><function>g_thread_pool_new()</function></link>. Instead the maximal number of threads only
242
has effect for the allocation of new threads in <link linkend="g-thread-pool-push"><function>g_thread_pool_push()</function></link>.
243
A new thread is allocated, whenever the number of currently
244
running threads in <parameter>pool</parameter> is smaller than the maximal number.
247
<parameter>error</parameter> can be <link linkend="NULL--CAPS"><literal>NULL</literal></link> to ignore errors, or non-<link linkend="NULL--CAPS"><literal>NULL</literal></link> to report
248
errors. An error can only occur when a new thread couldn't be
251
</para><variablelist role="params">
252
<varlistentry><term><parameter>pool</parameter> :</term>
253
<listitem><simpara> a <link linkend="GThreadPool"><type>GThreadPool</type></link>
254
</simpara></listitem></varlistentry>
255
<varlistentry><term><parameter>max_threads</parameter> :</term>
256
<listitem><simpara> a new maximal number of threads for <parameter>pool</parameter>
257
</simpara></listitem></varlistentry>
258
<varlistentry><term><parameter>error</parameter> :</term>
259
<listitem><simpara> return location for error
260
</simpara></listitem></varlistentry>
261
</variablelist></refsect2>
262
<refsect2 id="g-thread-pool-get-max-threads" role="function">
263
<title>g_thread_pool_get_max_threads ()</title>
264
<indexterm zone="g-thread-pool-get-max-threads"><primary sortas="thread_pool_get_max_threads">g_thread_pool_get_max_threads</primary></indexterm><programlisting><link linkend="gint">gint</link> g_thread_pool_get_max_threads (<link linkend="GThreadPool">GThreadPool</link> *pool);</programlisting>
266
Returns the maximal number of threads for <parameter>pool</parameter>.</para>
268
</para><variablelist role="params">
269
<varlistentry><term><parameter>pool</parameter> :</term>
270
<listitem><simpara> a <link linkend="GThreadPool"><type>GThreadPool</type></link>
271
</simpara></listitem></varlistentry>
272
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> the maximal number of threads
273
</simpara></listitem></varlistentry>
274
</variablelist></refsect2>
275
<refsect2 id="g-thread-pool-get-num-threads" role="function">
276
<title>g_thread_pool_get_num_threads ()</title>
277
<indexterm zone="g-thread-pool-get-num-threads"><primary sortas="thread_pool_get_num_threads">g_thread_pool_get_num_threads</primary></indexterm><programlisting><link linkend="guint">guint</link> g_thread_pool_get_num_threads (<link linkend="GThreadPool">GThreadPool</link> *pool);</programlisting>
279
Returns the number of threads currently running in <parameter>pool</parameter>.</para>
281
</para><variablelist role="params">
282
<varlistentry><term><parameter>pool</parameter> :</term>
283
<listitem><simpara> a <link linkend="GThreadPool"><type>GThreadPool</type></link>
284
</simpara></listitem></varlistentry>
285
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> the number of threads currently running
286
</simpara></listitem></varlistentry>
287
</variablelist></refsect2>
288
<refsect2 id="g-thread-pool-unprocessed" role="function">
289
<title>g_thread_pool_unprocessed ()</title>
290
<indexterm zone="g-thread-pool-unprocessed"><primary sortas="thread_pool_unprocessed">g_thread_pool_unprocessed</primary></indexterm><programlisting><link linkend="guint">guint</link> g_thread_pool_unprocessed (<link linkend="GThreadPool">GThreadPool</link> *pool);</programlisting>
292
Returns the number of tasks still unprocessed in <parameter>pool</parameter>.</para>
294
</para><variablelist role="params">
295
<varlistentry><term><parameter>pool</parameter> :</term>
296
<listitem><simpara> a <link linkend="GThreadPool"><type>GThreadPool</type></link>
297
</simpara></listitem></varlistentry>
298
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> the number of unprocessed tasks
299
</simpara></listitem></varlistentry>
300
</variablelist></refsect2>
301
<refsect2 id="g-thread-pool-free" role="function">
302
<title>g_thread_pool_free ()</title>
303
<indexterm zone="g-thread-pool-free"><primary sortas="thread_pool_free">g_thread_pool_free</primary></indexterm><programlisting><link linkend="void">void</link> g_thread_pool_free (<link linkend="GThreadPool">GThreadPool</link> *pool,
304
<link linkend="gboolean">gboolean</link> immediate,
305
<link linkend="gboolean">gboolean</link> wait_);</programlisting>
307
Frees all resources allocated for <parameter>pool</parameter>.
310
If <parameter>immediate</parameter> is <link linkend="TRUE--CAPS"><literal>TRUE</literal></link>, no new task is processed for
311
<parameter>pool</parameter>. Otherwise <parameter>pool</parameter> is not freed before the last task is
312
processed. Note however, that no thread of this pool is
313
interrupted, while processing a task. Instead at least all still
314
running threads can finish their tasks before the <parameter>pool</parameter> is freed.
317
If <parameter>wait_</parameter> is <link linkend="TRUE--CAPS"><literal>TRUE</literal></link>, the functions does not return before all tasks
318
to be processed (dependent on <parameter>immediate</parameter>, whether all or only the
319
currently running) are ready. Otherwise the function returns immediately.
322
After calling this function <parameter>pool</parameter> must not be used anymore.</para>
324
</para><variablelist role="params">
325
<varlistentry><term><parameter>pool</parameter> :</term>
326
<listitem><simpara> a <link linkend="GThreadPool"><type>GThreadPool</type></link>
327
</simpara></listitem></varlistentry>
328
<varlistentry><term><parameter>immediate</parameter> :</term>
329
<listitem><simpara> should <parameter>pool</parameter> shut down immediately?
330
</simpara></listitem></varlistentry>
331
<varlistentry><term><parameter>wait_</parameter> :</term>
332
<listitem><simpara> should the function wait for all tasks to be finished?
333
</simpara></listitem></varlistentry>
334
</variablelist></refsect2>
335
<refsect2 id="g-thread-pool-set-max-unused-threads" role="function">
336
<title>g_thread_pool_set_max_unused_threads ()</title>
337
<indexterm zone="g-thread-pool-set-max-unused-threads"><primary sortas="thread_pool_set_max_unused_threads">g_thread_pool_set_max_unused_threads</primary></indexterm><programlisting><link linkend="void">void</link> g_thread_pool_set_max_unused_threads
338
(<link linkend="gint">gint</link> max_threads);</programlisting>
340
Sets the maximal number of unused threads to <parameter>max_threads</parameter>. If
341
<parameter>max_threads</parameter> is -1, no limit is imposed on the number of unused
344
</para><variablelist role="params">
345
<varlistentry><term><parameter>max_threads</parameter> :</term>
346
<listitem><simpara> maximal number of unused threads
347
</simpara></listitem></varlistentry>
348
</variablelist></refsect2>
349
<refsect2 id="g-thread-pool-get-max-unused-threads" role="function">
350
<title>g_thread_pool_get_max_unused_threads ()</title>
351
<indexterm zone="g-thread-pool-get-max-unused-threads"><primary sortas="thread_pool_get_max_unused_threads">g_thread_pool_get_max_unused_threads</primary></indexterm><programlisting><link linkend="gint">gint</link> g_thread_pool_get_max_unused_threads
352
(void);</programlisting>
354
Returns the maximal allowed number of unused threads.</para>
356
</para><variablelist role="params">
357
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> the maximal number of unused threads
358
</simpara></listitem></varlistentry>
359
</variablelist></refsect2>
360
<refsect2 id="g-thread-pool-get-num-unused-threads" role="function">
361
<title>g_thread_pool_get_num_unused_threads ()</title>
362
<indexterm zone="g-thread-pool-get-num-unused-threads"><primary sortas="thread_pool_get_num_unused_threads">g_thread_pool_get_num_unused_threads</primary></indexterm><programlisting><link linkend="guint">guint</link> g_thread_pool_get_num_unused_threads
363
(void);</programlisting>
365
Returns the number of currently unused threads.</para>
367
</para><variablelist role="params">
368
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> the number of currently unused threads
369
</simpara></listitem></varlistentry>
370
</variablelist></refsect2>
371
<refsect2 id="g-thread-pool-stop-unused-threads" role="function">
372
<title>g_thread_pool_stop_unused_threads ()</title>
373
<indexterm zone="g-thread-pool-stop-unused-threads"><primary sortas="thread_pool_stop_unused_threads">g_thread_pool_stop_unused_threads</primary></indexterm><programlisting><link linkend="void">void</link> g_thread_pool_stop_unused_threads (void);</programlisting>
375
Stops all currently unused threads. This does not change the
376
maximal number of unused threads. This function can be used to
377
regularly stop all unused threads e.g. from <link linkend="g-timeout-add"><function>g_timeout_add()</function></link>.</para>
380
<refsect2 id="g-thread-pool-set-sort-function" role="function" condition="since:2.10">
381
<title>g_thread_pool_set_sort_function ()</title>
382
<indexterm zone="g-thread-pool-set-sort-function" role="2.10"><primary sortas="thread_pool_set_sort_function">g_thread_pool_set_sort_function</primary></indexterm><programlisting><link linkend="void">void</link> g_thread_pool_set_sort_function (<link linkend="GThreadPool">GThreadPool</link> *pool,
383
<link linkend="GCompareDataFunc">GCompareDataFunc</link> func,
384
<link linkend="gpointer">gpointer</link> user_data);</programlisting>
386
Sets the function used to sort the list of tasks. This allows the
387
tasks to be processed by a priority determined by <parameter>func</parameter>, and not
388
just in the order in which they were added to the pool.
391
Note, if the maximum number of threads is more than 1, the order
392
that threads are executed can not be guranteed 100%. Threads are
393
scheduled by the operating system and are executed at random. It
394
cannot be assumed that threads are executed in the order they are
397
</para><variablelist role="params">
398
<varlistentry><term><parameter>pool</parameter> :</term>
399
<listitem><simpara> a <link linkend="GThreadPool"><type>GThreadPool</type></link>
400
</simpara></listitem></varlistentry>
401
<varlistentry><term><parameter>func</parameter> :</term>
402
<listitem><simpara> the <link linkend="GCompareDataFunc"><type>GCompareDataFunc</type></link> used to sort the list of tasks.
403
This function is passed two tasks. It should return
404
0 if the order in which they are handled does not matter,
405
a negative value if the first task should be processed before
406
the second or a positive value if the second task should be
408
</simpara></listitem></varlistentry>
409
<varlistentry><term><parameter>user_data</parameter> :</term>
410
<listitem><simpara> user data passed to <parameter>func</parameter>.
411
</simpara></listitem></varlistentry>
412
</variablelist><para role="since">Since 2.10</para></refsect2>
413
<refsect2 id="g-thread-pool-set-max-idle-time" role="function" condition="since:2.10">
414
<title>g_thread_pool_set_max_idle_time ()</title>
415
<indexterm zone="g-thread-pool-set-max-idle-time" role="2.10"><primary sortas="thread_pool_set_max_idle_time">g_thread_pool_set_max_idle_time</primary></indexterm><programlisting><link linkend="void">void</link> g_thread_pool_set_max_idle_time (<link linkend="guint">guint</link> interval);</programlisting>
417
This function will set the maximum <parameter>interval</parameter> that a thread waiting
418
in the pool for new tasks can be idle for before being
419
stopped. This function is similar to calling
420
<link linkend="g-thread-pool-stop-unused-threads"><function>g_thread_pool_stop_unused_threads()</function></link> on a regular timeout, except,
421
this is done on a per thread basis.
424
By setting <parameter>interval</parameter> to 0, idle threads will not be stopped.
426
This function makes use of <link linkend="g-async-queue-timed-pop"><function>g_async_queue_timed_pop()</function></link> using
427
<parameter>interval</parameter>.</para>
429
</para><variablelist role="params">
430
<varlistentry><term><parameter>interval</parameter> :</term>
431
<listitem><simpara> the maximum <parameter>interval</parameter> (1/1000ths of a second) a thread
433
</simpara></listitem></varlistentry>
434
</variablelist><para role="since">Since 2.10</para></refsect2>
435
<refsect2 id="g-thread-pool-get-max-idle-time" role="function" condition="since:2.10">
436
<title>g_thread_pool_get_max_idle_time ()</title>
437
<indexterm zone="g-thread-pool-get-max-idle-time" role="2.10"><primary sortas="thread_pool_get_max_idle_time">g_thread_pool_get_max_idle_time</primary></indexterm><programlisting><link linkend="guint">guint</link> g_thread_pool_get_max_idle_time (void);</programlisting>
439
This function will return the maximum <parameter>interval</parameter> that a thread will
440
wait in the thread pool for new tasks before being stopped.
443
If this function returns 0, threads waiting in the thread pool for
444
new work are not stopped.</para>
446
</para><variablelist role="params">
447
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> the maximum <parameter>interval</parameter> to wait for new tasks in the
448
thread pool before stopping the thread (1/1000ths of a second).
450
</simpara></listitem></varlistentry>
451
</variablelist><para role="since">Since 2.10</para></refsect2>
457
<refsect1 id="glib-Thread-Pools.see-also">
458
<title>See Also</title>
459
<para> <variablelist> <varlistentry>
460
<term><link linkend="GThread"><type>GThread</type></link></term> <listitem><para>GLib thread
461
system.</para></listitem> </varlistentry> </variablelist>