ThreadPool

The glib.ThreadPool 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.

Constructors

this
this(GThreadPool* gThreadPool, bool ownedRef)

Sets our main struct and passes it to the parent class.

this
this(GFunc func, void* userData, int maxThreads, bool exclusive)

This function creates a new thread pool.

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Members

Functions

free
void free(bool immediate, bool wait)

Frees all resources allocated for pool.

getMaxThreads
int getMaxThreads()

Returns the maximal number of threads for pool.

getNumThreads
uint getNumThreads()

Returns the number of threads currently running in pool.

getStruct
void* getStruct()

the main Gtk struct as a void*

getThreadPoolStruct
GThreadPool* getThreadPoolStruct(bool transferOwnership)

Get the main Gtk struct

moveToFront
bool moveToFront(void* data)

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

push
bool push(void* data)

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

setMaxThreads
bool setMaxThreads(int maxThreads)

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.

setSortFunction
void setSortFunction(GCompareDataFunc func, void* userData)

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.

unprocessed
uint unprocessed()

Returns the number of tasks still unprocessed in pool.

Properties

exclusive
bool exclusive [@property getter]
bool exclusive [@property setter]

are all threads exclusive to this pool

func
GFunc func [@property getter]
GFunc func [@property setter]

the function to execute in the threads of this pool

userData
void* userData [@property getter]
void* userData [@property setter]

the user data for the threads of this pool

Static functions

getMaxIdleTime
uint getMaxIdleTime()

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

getMaxUnusedThreads
int getMaxUnusedThreads()

Returns the maximal allowed number of unused threads.

getNumUnusedThreads
uint getNumUnusedThreads()

Returns the number of currently unused threads.

setMaxIdleTime
void setMaxIdleTime(uint interval)

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 Thread.poolStopUnusedThreads on a regular timeout, except this is done on a per thread basis.

setMaxUnusedThreads
void setMaxUnusedThreads(int maxThreads)

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.

stopUnusedThreads
void stopUnusedThreads()

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 Timeout.add.

Variables

gThreadPool
GThreadPool* gThreadPool;

the main Gtk struct