1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 pools of threads to execute work concurrently
7 <!-- ##### SECTION Long_Description ##### -->
9 Sometimes you wish to asynchronously fork out the execution of work and
10 continue working in your own thread. If that will happen often, the
11 overhead of starting and destroying a thread each time might be too
12 high. In such cases reusing already started threads seems like a good
13 idea. And it indeed is, but implementing this can be tedious and
18 Therefore GLib provides thread pools for your convenience. An added
19 advantage is, that the threads can be shared between the different
20 subsystems of your program, when they are using GLib.
24 To create a new thread pool, you use g_thread_pool_new(). It is
25 destroyed by g_thread_pool_free().
29 If you want to execute a certain task within a thread pool, you call
34 To get the current number of running threads you call
35 g_thread_pool_get_num_threads(). To get the number of still
36 unprocessed tasks you call g_thread_pool_unprocessed(). To control the
37 maximal number of threads for a thread pool, you use
38 g_thread_pool_get_max_threads() and g_thread_pool_set_max_threads().
42 Finally you can control the number of unused threads, that are kept
43 alive by GLib for future use. The current number can be fetched with
44 g_thread_pool_get_num_unused_threads(). The maximal number can be
45 controlled by g_thread_pool_get_max_unused_threads() and
46 g_thread_pool_set_max_unused_threads(). All currently unused threads
47 can be stopped by calling g_thread_pool_stop_unused_threads().
50 <!-- ##### SECTION See_Also ##### -->
56 <listitem><para>GLib thread system.</para></listitem>
62 <!-- ##### SECTION Stability_Level ##### -->
65 <!-- ##### STRUCT GThreadPool ##### -->
67 The #GThreadPool struct represents a thread pool. It has six public
68 read-only members, but the underlying struct is bigger, so you must not copy
72 @func: the function to execute in the threads of this pool
73 @user_data: the user data for the threads of this pool
74 @exclusive: are all threads exclusive to this pool
76 <!-- ##### FUNCTION g_thread_pool_new ##### -->
89 <!-- ##### FUNCTION g_thread_pool_push ##### -->
99 <!-- ##### FUNCTION g_thread_pool_set_max_threads ##### -->
109 <!-- ##### FUNCTION g_thread_pool_get_max_threads ##### -->
118 <!-- ##### FUNCTION g_thread_pool_get_num_threads ##### -->
127 <!-- ##### FUNCTION g_thread_pool_unprocessed ##### -->
136 <!-- ##### FUNCTION g_thread_pool_free ##### -->
146 <!-- ##### FUNCTION g_thread_pool_set_max_unused_threads ##### -->
154 <!-- ##### FUNCTION g_thread_pool_get_max_unused_threads ##### -->
162 <!-- ##### FUNCTION g_thread_pool_get_num_unused_threads ##### -->
170 <!-- ##### FUNCTION g_thread_pool_stop_unused_threads ##### -->
177 <!-- ##### FUNCTION g_thread_pool_set_sort_function ##### -->
187 <!-- ##### FUNCTION g_thread_pool_set_max_idle_time ##### -->
195 <!-- ##### FUNCTION g_thread_pool_get_max_idle_time ##### -->