typedef typedefG_BEGIN_DECLS struct _GThreadPool | GThreadPool |
IMPORT_C GThreadPool * | g_thread_pool_new | ( | GFunc | func, |
gpointer | user_data, | |||
gint | max_threads, | |||
gboolean | exclusive, | |||
GError ** | error | |||
) |
g_thread_pool_new: : a function to execute in the threads of the new thread pool : user data that is handed over to every time it is called : the maximal number of threads to execute concurrently in the new thread pool, -1 means no limit : should this thread pool be exclusive? : return location for error
This function creates a new thread pool.
Whenever you call g_thread_pool_push(), either a new thread is created or an unused one is reused. At most threads are running concurrently for this thread pool. = -1 allows unlimited threads to be created for this thread pool. The newly created or reused thread now executes the function with the two arguments. The first one is the parameter to g_thread_pool_push() and the second one is .
The parameter determines, whether the thread pool owns all threads exclusive or whether the threads are shared globally. If is TRUE, threads are started immediately and they will run exclusively for this thread pool until it is destroyed by g_thread_pool_free(). If is FALSE, threads are created, when needed and shared between all non-exclusive thread pools. This implies that may not be -1 for exclusive thread pools.
can be NULL to ignore errors, or non-NULL to report errors. An error can only occur when is set to TRUE and not all threads could be created.
Return value: the new GThreadPool
IMPORT_C void | g_thread_pool_push | ( | GThreadPool * | pool, |
gpointer | data, | |||
GError ** | error | |||
) |
g_thread_pool_push: : a GThreadPool : a new task for : return location for error
Inserts into the list of tasks to be executed by . When the number of currently running threads is lower than the maximal allowed number of threads, a new thread is started (or reused) with the properties given to g_thread_pool_new (). Otherwise stays in the queue until a thread in this pool finishes its previous task and processes .
can be NULL to ignore errors, or non-NULL to report errors. An error can only occur when a new thread couldn't be created. In that case is simply appended to the queue of work to do.
IMPORT_C void | g_thread_pool_set_max_threads | ( | GThreadPool * | pool, |
gint | max_threads, | |||
GError ** | error | |||
) |
g_thread_pool_set_max_threads: : a GThreadPool : a new maximal number of threads for : return location for error
Sets the maximal allowed number of threads for . A value of -1 means, that the maximal number of threads is unlimited.
Setting to 0 means stopping all work for . It is effectively frozen until is set to a non-zero value again.
A thread is never terminated while calling , as supplied by g_thread_pool_new (). Instead the maximal number of threads only has effect for the allocation of new threads in g_thread_pool_push(). A new thread is allocated, whenever the number of currently running threads in is smaller than the maximal number.
can be NULL to ignore errors, or non-NULL to report errors. An error can only occur when a new thread couldn't be created.
IMPORT_C gint | g_thread_pool_get_max_threads | ( | GThreadPool * | pool | ) |
g_thread_pool_get_max_threads: : a GThreadPool
Returns the maximal number of threads for .
Return value: the maximal number of threads
IMPORT_C guint | g_thread_pool_get_num_threads | ( | GThreadPool * | pool | ) |
g_thread_pool_get_num_threads: : a GThreadPool
Returns the number of threads currently running in .
Return value: the number of threads currently running
IMPORT_C guint | g_thread_pool_unprocessed | ( | GThreadPool * | pool | ) |
g_thread_pool_unprocessed: : a GThreadPool
Returns the number of tasks still unprocessed in .
Return value: the number of unprocessed tasks
IMPORT_C void | g_thread_pool_free | ( | GThreadPool * | pool, |
gboolean | immediate, | |||
gboolean | wait_ | |||
) |
g_thread_pool_free: : a GThreadPool : should shut down immediately? : should the function wait for all tasks to be finished?
Frees all resources allocated for .
If is TRUE, no new task is processed for . Otherwise is not freed before the last task is processed. Note however, that no thread of this pool is interrupted, while processing a task. Instead at least all still running threads can finish their tasks before the is freed.
If is TRUE, the functions does not return before all tasks to be processed (dependent on , whether all or only the currently running) are ready. Otherwise the function returns immediately.
After calling this function must not be used anymore.
IMPORT_C void | g_thread_pool_set_max_unused_threads | ( | gint | max_threads | ) |
g_thread_pool_set_max_unused_threads: : maximal number of unused threads
Sets the maximal number of unused threads to . If is -1, no limit is imposed on the number of unused threads.
IMPORT_C gint | g_thread_pool_get_max_unused_threads | ( | void | ) |
g_thread_pool_get_max_unused_threads:
Returns the maximal allowed number of unused threads.
Return value: the maximal number of unused threads
IMPORT_C guint | g_thread_pool_get_num_unused_threads | ( | void | ) |
g_thread_pool_get_num_unused_threads:
Returns the number of currently unused threads.
Return value: the number of currently unused threads
IMPORT_C void | g_thread_pool_stop_unused_threads | ( | void | ) |
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().
IMPORT_C void | g_thread_pool_set_sort_function | ( | GThreadPool * | pool, |
GCompareDataFunc | func, | |||
gpointer | user_data | |||
) |
g_thread_pool_set_sort_function: : a GThreadPool : the GCompareDataFunc used to sort the list of tasks. This function is passed two tasks. It should return 0 if the order in which they are handled does not matter, a negative value if the first task should be processed before the second or a positive value if the second task should be processed first. : user data passed to .
Sets the function used to sort the list of tasks. This allows the tasks to be processed by a priority determined by , and not just in the order in which they were added to the pool.
Note, if the maximum number of threads is more than 1, the order that threads are executed can not be guranteed 100%. Threads are scheduled by the operating system and are executed at random. It cannot be assumed that threads are executed in the order they are created.
Since: 2.10
IMPORT_C void | g_thread_pool_set_max_idle_time | ( | guint | interval | ) |
g_thread_pool_set_max_idle_time: : the maximum (1/1000ths of a second) a thread can be idle.
This function will set the maximum 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.
By setting to 0, idle threads will not be stopped.
This function makes use of g_async_queue_timed_pop () using .
Since: 2.10
IMPORT_C guint | g_thread_pool_get_max_idle_time | ( | void | ) |
g_thread_pool_get_max_idle_time:
This function will return the maximum that a thread will wait in the thread pool for new tasks before being stopped.
If this function returns 0, threads waiting in the thread pool for new work are not stopped.
Return value: the maximum to wait for new tasks in the thread pool before stopping the thread (1/1000ths of a second).
Since: 2.10