Search code examples
winapicritical-section

InitializeCriticalSectionAndSpinCount, is there a default Spin Count?


The API method InitializeCriticalSectionAndSpinCount allows you to set a spin count so when EnterCriticalSection is called, it loops using a spinlock to try to acquire the resource some number of times. Only if all the attempts fail does the thread transition to kernel mode to enter a wait state.

If the 'normal' InitializeCriticalSection() is called instead, is there a 'default' spin count set? (Or is it 0, no spin?)


Solution

  • Quoting from this article:

    SpinCount ... This field defaults to zero, but can be set to a different value with the InitializeCriticalSectionAndSpinCount API

    So the default is no spin.