### Function Macro

# GLib once

since: 2.4

#### Declaration [src]

    #define g_once (
      once,
      func,
      arg
    )

#### Description [src]

The first call to this routine by a process with a given `GOnce` struct calls `func` with the given argument. Thereafter, subsequent calls to `g_once()` with the same `GOnce` struct do not call `func` again, but return the stored result of the first call. On return from g_once(), the status of `once` will be `G_ONCE_STATUS_READY`.

For example, a mutex or a thread-specific data key must be created exactly once. In a threaded environment, calling `g_once()` ensures that the initialization is serialized across multiple threads.

Calling `g_once()` recursively on the same `GOnce` struct in `func` will lead to a deadlock.

      gpointer
      get_debug_flags (void)
      {
        static GOnce my_once = G_ONCE_INIT;

        g_once (&my_once, parse_debug_flags, NULL);

        return my_once.retval;
      }

Available since: 2.4

This function is not directly available to language bindings.

#### Parameters

`once`

  Type: `-`

  A `GOnce` structure.

`func`

  Type: `-`

  The `GThreadFunc` function associated to `once`. This function is called only once, regardless of the number of times it and its associated `GOnce` struct are passed to g_once().

`arg`

  Type: `-`

  Data to be passed to `func`.