Thread

The glib.Thread struct represents a running thread. This struct is returned by Thread.new or Thread.tryNew. You can obtain the glib.Thread struct representing the current thread by calling Thread.self.

GThread is refcounted, see Thread.ref and Thread.unref. The thread represented by it holds a reference while it is running, and Thread.join consumes the reference that it is given, so it is normally not necessary to manage GThread references explicitly.

The structure is opaque -- none of its fields may be directly accessed.

Constructors

this
this(GThread* gThread, bool ownedRef)

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

this
this(string name, GThreadFunc func, void* data)

This function is the same as Thread.new except that it allows for the possibility of failure.

Destructor

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

Members

Functions

getStruct
void* getStruct()

the main Gtk struct as a void*

getThreadStruct
GThread* getThreadStruct(bool transferOwnership)

Get the main Gtk struct

join
void* join()

Waits until thread finishes, i.e. the function func, as given to Thread.new, returns or Thread.exit is called. If thread has already terminated, then Thread.join returns immediately.

ref_
Thread ref_()

Increase the reference count on thread.

unref
void unref()

Decrease the reference count on thread, possibly freeing all resources associated with it.

Static functions

bitLock
void bitLock(int* address, int lockBit)

Sets the indicated lock_bit in address. If the bit is already set, this call will block until g_bit_unlock() unsets the corresponding bit.

bitTrylock
bool bitTrylock(int* address, int lockBit)

Sets the indicated lock_bit in address, returning TRUE if successful. If the bit is already set, returns FALSE immediately.

bitUnlock
void bitUnlock(int* address, int lockBit)

Clears the indicated lock_bit in address. If another thread is currently blocked in g_bit_lock() on this same bit then it will be woken up.

errorQuark
GQuark errorQuark()
exit
void exit(void* retval)

Terminates the current thread.

getNumProcessors
uint getNumProcessors()

Determine the approximate number of threads that the system will schedule simultaneously for this process. This is intended to be used as a parameter to Thread.poolNew for CPU bound tasks and similar cases.

pointerBitLock
void pointerBitLock(void* address, int lockBit)

This is equivalent to g_bit_lock, but working on pointers (or other pointer-sized values).

pointerBitTrylock
bool pointerBitTrylock(void* address, int lockBit)

This is equivalent to g_bit_trylock, but working on pointers (or other pointer-sized values).

pointerBitUnlock
void pointerBitUnlock(void* address, int lockBit)

This is equivalent to g_bit_unlock, but working on pointers (or other pointer-sized values).

self
Thread self()

This function returns the glib.Thread corresponding to the current thread. Note that this function does not increase the reference count of the returned struct.

yield
void yield()

Causes the calling thread to voluntarily relinquish the CPU, so that other threads can run.

Variables

gThread
GThread* gThread;

the main Gtk struct