7

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?)

Ajay
  • 18,086
  • 12
  • 59
  • 105
Darian Miller
  • 7,808
  • 3
  • 43
  • 62

1 Answers1

8

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.

Praetorian
  • 106,671
  • 19
  • 240
  • 328
  • 1
    Thanks for the link... it also stated "This field defaults to zero, but can be set to a different value with the InitializeCriticalSectionAndSpinCount API." – Darian Miller Dec 17 '10 at 23:12
  • Hey, no prob. You gave the requested info in the link. :) – Darian Miller Dec 19 '10 at 17:04
  • 1
    Link no longer working. **[New link](https://web.archive.org/web/20150419055323/https://msdn.microsoft.com/en-us/magazine/cc164040.aspx)**. BTW @Praetorian you can edit your post to make it correct ;) – rustyx Jan 13 '16 at 08:23
  • 1
    @rustyx Thanks for the new link. I updated the answer to remove the incorrect info. I was very new to SO back when I posted this, and somehow thought changing the whole answer in an edit would be frowned upon :) – Praetorian Jan 15 '16 at 18:50