Function Macro



#define g_once (


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.

  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


once none

A GOnce structure.

func none

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 none

Data to be passed to func.