GLib.Mutex

Fields

Name

Type

Access

Description

i

[int]

r

p

object

r

Methods

clear ()

init ()

lock ()

trylock ()

unlock ()

Details

class GLib.Mutex
clear()[source]

Frees the resources allocated to a mutex with GLib.Mutex.init().

This function should not be used with a GLib.Mutex that has been statically allocated.

Calling GLib.Mutex.clear() on a locked mutex leads to undefined behaviour.

New in version 2.32.

init()[source]

Initializes a GLib.Mutex so that it can be used.

This function is useful to initialize a mutex that has been allocated on the stack, or as part of a larger structure. It is not necessary to initialize a mutex that has been statically allocated.

typedef struct {
    GMutex m;
    ...
  } Blob;

Blob *b;

b = g_new (Blob, 1);
g_mutex_init (&b->m);

To undo the effect of GLib.Mutex.init() when a mutex is no longer needed, use GLib.Mutex.clear().

Calling GLib.Mutex.init() on an already initialized GLib.Mutex leads to undefined behaviour.

New in version 2.32.

lock()[source]

Locks self. If self is already locked by another thread, the current thread will block until self is unlocked by the other thread.

GLib.Mutex is neither guaranteed to be recursive nor to be non-recursive. As such, calling GLib.Mutex.lock() on a GLib.Mutex that has already been locked by the same thread results in undefined behaviour (including but not limited to deadlocks).

trylock()[source]
Returns:

True if self could be locked

Return type:

bool

Tries to lock self. If self is already locked by another thread, it immediately returns False. Otherwise it locks self and returns True.

GLib.Mutex is neither guaranteed to be recursive nor to be non-recursive. As such, calling GLib.Mutex.lock() on a GLib.Mutex that has already been locked by the same thread results in undefined behaviour (including but not limited to deadlocks or arbitrary return values).

unlock()[source]

Unlocks self. If another thread is blocked in a GLib.Mutex.lock() call for self, it will become unblocked and can lock self itself.

Calling GLib.Mutex.unlock() on a mutex that is not locked by the current thread leads to undefined behaviour.