Function

GLibThreadPoolnew

Declaration [src]

GThreadPool*
g_thread_pool_new (
  GFunc func,
  gpointer user_data,
  gint max_threads,
  gboolean exclusive,
  GError** error
)

Description [src]

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 max_threads threads are running concurrently for this thread pool. max_threads = -1 allows unlimited threads to be created for this thread pool. The newly created or reused thread now executes the function func with the two arguments. The first one is the parameter to g_thread_pool_push() and the second one is user_data.

Pass g_get_num_processors() to max_threads to create as many threads as there are logical processors on the system. This will not pin each thread to a specific processor.

The parameter exclusive determines whether the thread pool owns all threads exclusive or shares them with other thread pools. If exclusive is TRUE, max_threads threads are started immediately and they will run exclusively for this thread pool until it is destroyed by g_thread_pool_free(). If exclusive is FALSE, threads are created when needed and shared between all non-exclusive thread pools. This implies that max_threads may not be -1 for exclusive thread pools. Besides, exclusive thread pools are not affected by g_thread_pool_set_max_idle_time() since their threads are never considered idle and returned to the global pool.

Note that the threads used by exclusive thread pools will all inherit the scheduler settings of the current thread while the threads used by non-exclusive thread pools will inherit the scheduler settings from the first thread that created such a thread pool.

At least one thread will be spawned when this function is called, either to create the max_threads exclusive threads, or to preserve the scheduler settings of the current thread for future spawns.

error can be NULL to ignore errors, or non-NULL to report errors. An error can only occur when exclusive is set to TRUE and not all max_threads threads could be created. See GThreadError for possible errors that may occur. Note, even in case of error a valid GThreadPool is returned.

This function is not directly available to language bindings.

Parameters

func

Type: GFunc

A function to execute in the threads of the new thread pool.

user_data

Type: gpointer

User data that is handed over to func every time it is called.

The argument can be NULL.
The data is owned by the caller of the function.
max_threads

Type: gint

The maximal number of threads to execute concurrently in the new thread pool, -1 means no limit.

exclusive

Type: gboolean

Should this thread pool be exclusive?

error

Type: GError **

The return location for a recoverable error.

The argument can be NULL.
If the return location is not NULL, then you must initialize it to a NULL GError*.
The argument will be left initialized to NULL by the function if there are no errors.
In case of error, the argument will be set to a newly allocated GError; the caller will take ownership of the data, and be responsible for freeing it.

Return value

Type: GThreadPool

The new GThreadPool.

The data is owned by the called function.