<GThread>

<GThread>

Description

The GThread struct represents a running thread. This struct is returned by g_thread_new() or g_thread_try_new(). You can obtain the GThread struct representing the current thread by calling g_thread_self().

GThread is refcounted, see g_thread_ref() and g_thread_unref(). The thread represented by it holds a reference while it is running, and g_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.

Functions

join

(define-values (%return) (thread:join self))

Waits until thread finishes, i.e. the function func, as given to g_thread_new(), returns or g_thread_exit() is called. If thread has already terminated, then g_thread_join() returns immediately.

Any thread can wait for any other thread by calling g_thread_join(), not just its 'creator'. Calling g_thread_join() from multiple threads for the same thread leads to undefined behaviour.

The value returned by func or given to g_thread_exit() is returned by this function.

g_thread_join() consumes the reference to the passed-in thread. This will usually cause the GThread struct and associated resources to be freed. Use g_thread_ref() to obtain an extra reference if you want to keep the GThread alive beyond the g_thread_join() call.

Parameters

thread

a GThread

Passed as self

ref

(define-values (%return) (thread:ref self))

Increase the reference count on thread.

Parameters

thread

a GThread

Passed as self

unref

(define-values () (thread:unref self))

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

Note that each thread holds a reference to its GThread while it is running, so it is safe to drop your own reference to it if you don't need it anymore.

Parameters

thread

a GThread

Passed as self

thread:try-new

(define-values (%return) (thread:try-new name func data))

Undocumented

Parameters

name

Passed as name

func

Passed as func

data

Passed as data

thread:new

(define-values (%return) (thread:new name func data))

Undocumented

Parameters

name

Passed as name

func

Passed as func

data

Passed as data

thread:error-quark

(define-values (%return) (thread:error-quark))

Undocumented

thread:exit

(define-values () (thread:exit retval))

Terminates the current thread.

If another thread is waiting for us using g_thread_join() then the waiting thread will be woken up and get retval as the return value of g_thread_join().

Calling g_thread_exit() with a parameter retval is equivalent to returning retval from the function func, as given to g_thread_new().

You must only call g_thread_exit() from a thread that you created yourself with g_thread_new() or related APIs. You must not call this function from a thread created with another threading library or or from within a GThreadPool.

Parameters

retval

the return value of this thread

Passed as retval

thread:self

(define-values (%return) (thread:self))

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

This function will return a GThread even for threads that were not created by GLib (i.e. those created by other threading APIs). This may be useful for thread identification purposes (i.e. comparisons) but you must not use GLib functions (such as g_thread_join()) on these threads.

thread:yield

(define-values () (thread:yield))

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

This function is often used as a method to make busy wait less evil.