Struct

GLibThreadPool

Description

struct GThreadPool {
  GFunc func;
  gpointer user_data;
  gboolean exclusive;
}

The GThreadPool struct represents a thread pool. It has three public read-only members, but the underlying struct is bigger, so you must not copy this struct.

Structure members
func

The function to execute in the threads of this pool.

user_data

The user data for the threads of this pool.

exclusive

Are all threads exclusive to this pool.

Functions

g_thread_pool_get_max_idle_time

This function will return the maximum interval that a thread will wait in the thread pool for new tasks before being stopped.

Available since: 2.10

g_thread_pool_get_max_unused_threads

Returns the maximal allowed number of unused threads.

g_thread_pool_get_num_unused_threads

Returns the number of currently unused threads.

g_thread_pool_new

This function creates a new thread pool.

g_thread_pool_new_full

This function creates a new thread pool similar to g_thread_pool_new() but allowing item_free_func to be specified to free the data passed to g_thread_pool_push() in the case that the GThreadPool is stopped and freed before all tasks have been executed.

Available since: 2.70

g_thread_pool_set_max_idle_time

This function will set the maximum interval that a thread waiting in the pool for new tasks can be idle for before being stopped. This function is similar to calling g_thread_pool_stop_unused_threads() on a regular timeout, except this is done on a per thread basis.

Available since: 2.10

g_thread_pool_set_max_unused_threads

Sets the maximal number of unused threads to max_threads. If max_threads is -1, no limit is imposed on the number of unused threads.

g_thread_pool_stop_unused_threads

Stops all currently unused threads. This does not change the maximal number of unused threads. This function can be used to regularly stop all unused threads e.g. from g_timeout_add().

Instance methods

g_thread_pool_free

Frees all resources allocated for pool.

g_thread_pool_get_max_threads

Returns the maximal number of threads for pool.

g_thread_pool_get_num_threads

Returns the number of threads currently running in pool.

g_thread_pool_move_to_front

Moves the item to the front of the queue of unprocessed items, so that it will be processed next.

Available since: 2.46

g_thread_pool_push

Inserts data into the list of tasks to be executed by pool.

g_thread_pool_set_max_threads

Sets the maximal allowed number of threads for pool. A value of -1 means that the maximal number of threads is unlimited. If pool is an exclusive thread pool, setting the maximal number of threads to -1 is not allowed.

g_thread_pool_set_sort_function

Sets the function used to sort the list of tasks. This allows the tasks to be processed by a priority determined by func, and not just in the order in which they were added to the pool.

Available since: 2.10

g_thread_pool_unprocessed

Returns the number of tasks still unprocessed in pool.