InitOnceExecuteOnce function

Executes the specified function successfully one time. No other threads that specify the same one-time initialization structure can execute the specified function while it is being executed by the current thread.

Syntax

BOOL InitOnceExecuteOnce(
  PINIT_ONCE    InitOnce,
  PINIT_ONCE_FN InitFn,
  PVOID         Context,
  LPVOID        *Parameter
);

Parameters

InitOnce

A pointer to the one-time initialization structure.

InitFn

A pointer to an application-defined InitOnceCallback function.

Context

A parameter that receives data stored with the one-time initialization structure upon success. The low-order INIT_ONCE_CTX_RESERVED_BITS bits of the data are always zero.

Parameter

A parameter to be passed to the callback function.

Return Value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

This function is used for synchronous one-time initialization. For asynchronous one-time initialization, use the InitOnceBeginInitialize function with the INIT_ONCE_ASYNC flag.

Only one thread at a time can execute the callback function specified by InitFn. Other threads that specify the same one-time initialization structure block until the callback finishes.

To compile an application that uses this function, define _WIN32_WINNT as 0x0600 or later. For more information, see Using the Windows Headers.

Examples

For an example that uses this function, see Using One-Time Initialization.

Requirements

   
Windows version Windows Vista [desktop apps | UWP apps] Windows Server 2008 [desktop apps | UWP apps]
Target Platform Windows
Header synchapi.h (include Windows 7, Windows Server 2008 Windows Server 2008 R2, Windows.h)
Library Kernel32.lib
DLL Kernel32.dll

See Also

InitOnceCallback

InitOnceInitialize

One-Time Initialization

Synchronization Functions