ThreadPool

class ThreadPool(pointer: <Error class: unknown class><<Error class: unknown class>>, cleaner: <Error class: unknown class>? = null) : ProxyInstance

The GThreadPool struct represents a thread pool.

A thread pool is useful when you wish to asynchronously fork out the execution of work and continue working in your own thread. If that will happen often, the overhead of starting and destroying a thread each time might be too high. In such cases reusing already started threads seems like a good idea. And it indeed is, but implementing this can be tedious and error-prone.

Therefore GLib provides thread pools for your convenience. An added advantage is, that the threads can be shared between the different subsystems of your program, when they are using GLib.

To create a new thread pool, you use func@GLib.ThreadPool.new. It is destroyed by method@GLib.ThreadPool.free.

If you want to execute a certain task within a thread pool, use method@GLib.ThreadPool.push.

To get the current number of running threads you call method@GLib.ThreadPool.get_num_threads. To get the number of still unprocessed tasks you call method@GLib.ThreadPool.unprocessed. To control the maximum number of threads for a thread pool, you use method@GLib.ThreadPool.get_max_threads. and method@GLib.ThreadPool.set_max_threads.

Finally you can control the number of unused threads, that are kept alive by GLib for future use. The current number can be fetched with func@GLib.ThreadPool.get_num_unused_threads. The maximum number can be controlled by func@GLib.ThreadPool.get_max_unused_threads and func@GLib.ThreadPool.set_max_unused_threads. All currently unused threads can be stopped by calling func@GLib.ThreadPool.stop_unused_threads.

Skipped during bindings generation

  • field func: Func

Constructors

Link copied to clipboard
constructor()

Allocate a new ThreadPool.

constructor(scope: <Error class: unknown class>)

Allocate a new ThreadPool using the provided AutofreeScope.

constructor(userData: <Error class: unknown class>, exclusive: Boolean)

Allocate a new ThreadPool.

constructor(userData: <Error class: unknown class>, exclusive: Boolean, scope: <Error class: unknown class>)

Allocate a new ThreadPool using the provided AutofreeScope.

constructor(pointer: <Error class: unknown class><<Error class: unknown class>>, cleaner: <Error class: unknown class>? = null)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

are all threads exclusive to this pool

Link copied to clipboard
val glibThreadPoolPointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard
open override val handle: <Error class: unknown class>?
Link copied to clipboard
var userData: <Error class: unknown class>

the user data for the threads of this pool

Functions

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Compare two proxy instances for equality. This will compare both the type of the instances, and their memory addresses.

Link copied to clipboard
fun free(immediate: Boolean, wait: Boolean)

Frees all resources allocated for @pool.

Link copied to clipboard
fun getMaxThreads(): <Error class: unknown class>

Returns the maximal number of threads for @pool.

Link copied to clipboard
fun getNumThreads(): <Error class: unknown class>

Returns the number of threads currently running in @pool.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
fun moveToFront(data: <Error class: unknown class>? = null): Boolean

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

Link copied to clipboard
fun push(data: <Error class: unknown class>? = null): <Error class: unknown class><Boolean>

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

Link copied to clipboard
fun setMaxThreads(maxThreads: <Error class: unknown class>): <Error class: unknown class><Boolean>

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.

Link copied to clipboard

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.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun unprocessed(): <Error class: unknown class>

Returns the number of tasks still unprocessed in @pool.