Share via

InitializeCriticalSectionAndSpinCount (KernelBase) function

[This function is exported from KernelBase.dll in Windows 7 and Windows Server 2008 R2. This may change in subsequent versions. Instead of calling this function directly in KernelBase.dll, call the function through Kernel32.dll. See InitializeCriticalSectionAndSpinCount.]

Initializes a critical section object and sets the spin count for the critical section. Spinning means that when a thread tries to acquire a critical section that is locked, the thread enters a loop, checks to see if the lock is released, and if the lock is not released, the thread goes to sleep.


BOOL WINAPI InitializeCriticalSectionAndSpinCount(
  _Out_ LPCRITICAL_SECTION lpCriticalSection,
  _In_  DWORD              dwSpinCount


  • lpCriticalSection [out]
    A pointer to the critical section object.

  • dwSpinCount [in]
    The spin count for the critical section object. On single-processor systems, the spin count is ignored and the critical section spin count is set to 0 (zero). On multiprocessor systems, if the critical section is unavailable, the calling thread spin dwSpinCount times before performing a wait operation on a semaphore associated with the critical section. If the critical section becomes free during the spin operation, the calling thread avoids the wait operation.

Return value

If the function succeeds, the return value is nonzero.

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


Minimum supported client

Windows 7 [desktop apps | UWP apps]

Minimum supported server

Windows Server 2008 R2 [desktop apps | UWP apps]


Winbase.h (include Windows.h)