### Method

# GLib Mutex init

since: 2.32

#### Declaration

    void
    g_mutex_init (
      GMutex* mutex
    )

#### Description

Initializes a `GMutex` 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 `g_mutex_init()` when a mutex is no longer needed, use g_mutex_clear().

Calling `g_mutex_init()` on an already initialized `GMutex` leads to undefined behaviour.

Available since: 2.32