Expand Minimize

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 WINAPI InitOnceExecuteOnce(
  _Inout_      PINIT_ONCE InitOnce,
  _In_         PINIT_ONCE_FN InitFn,
  _Inout_opt_  PVOID Parameter,
  _Out_opt_    LPVOID *Context
);

Parameters

InitOnce [in, out]

A pointer to the one-time initialization structure.

InitFn [in]

A pointer to an application-defined InitOnceCallback function.

Parameter [in, out, optional]

A parameter to be passed to the callback function.

Context [out, optional]

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.

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.

Windows Phone 8: This API is supported.

Windows Phone 8.1: This API is supported.

Examples

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

Requirements

Minimum supported client

Windows Vista [desktop apps | Windows Store apps]

Minimum supported server

Windows Server 2008 [desktop apps | Windows Store apps]

Header

WinBase.h on Windows Vista, Windows 7, Windows Server 2008, and Windows Server 2008 R2 (include Windows.h);
Synchapi.h on Windows 8 and Windows Server 2012

Library

Kernel32.lib

DLL

Kernel32.dll

See also

InitOnceCallback
InitOnceInitialize
One-Time Initialization
Synchronization Functions

 

 

Community Additions

ADD
Show:
© 2014 Microsoft