Name Type Access Description
i [int] r  
p object r  


  clear ()
  init ()
  lock ()
  trylock ()
  unlock ()


class GLib.RecMutex

The GLib.RecMutex struct is an opaque data structure to represent a recursive mutex. It is similar to a GLib.Mutex with the difference that it is possible to lock a GLib.RecMutex multiple times in the same thread without deadlock. When doing so, care has to be taken to unlock the recursive mutex as often as it has been locked.

If a GLib.RecMutex is allocated in static storage then it can be used without initialisation. Otherwise, you should call GLib.RecMutex.init() on it and GLib.RecMutex.clear() when done.

A GLib.RecMutex should only be accessed with the g_rec_mutex_ functions.

New in version 2.32.


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

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

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

Sine: 2.32


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

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

It is not necessary to initialise a recursive mutex that has been statically allocated.

typedef struct {
    GRecMutex m;
  } Blob;

Blob *b;

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

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

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

New in version 2.32.


Locks self. If self is already locked by another thread, the current thread will block until self is unlocked by the other thread. If self is already locked by the current thread, the ‘lock count’ of self is increased. The mutex will only become available again when it is unlocked as many times as it has been locked.

New in version 2.32.

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.

New in version 2.32.


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

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

New in version 2.32.