3 ms·
Do you have a reference for this? AFAIK the win32 critical section (like any modern mutex implementation) first uses atomic instructions to check if anyone is
by YZF 7y ago
Do you have a reference for this? AFAIK the win32 critical section (like any modern mutex implementation) first uses atomic instructions to check if anyone is already in the critical section so it's really fast if no one is, and otherwise falls back to the OS synchronization objects.
- pizlonator 7y agoYour description and their description are not mutually exclusive.
- YZF 7y agoSpinning vs. a single check...
- gmueckl 7y agoThe information is right there in the documentation: https://docs.microsoft.com/en-us/windows/win32/sync/critical-section-objects https://docs.microsoft.com/en-us/windows/win32/sync/critical... The paragraph about InitializeCriticalSectionAndSpinCount and SetCriticalSectionSpinCount describe the behavior. IIRC, the default spin count used to be pretty high (1000 loops or so). Not sure if that was changed.
- YZF 7y agoInteresting. There's also that anecdote about the heap manager using a spin count of 4000. I wasn't aware this happened by default (I didn't see any mention of this in InitializeCriticalSection). I guess it's all down to the probability of contention vs. the amount of time the mutex is held.