|
Boost : |
From: Andy Sawyer (boost_at_[hidden])
Date: 2000-02-08 00:40:04
(Sorry, this is all VERY Win32 specific!)
On 08 February 2000 01:40, Borgerding, Mark A.wrote:
> Re: CRITICAL_SECTION
> I think the Win32 critical section mechanism basically uses
> spinlocks. The struct definition (in winnt.h) has a DWORD member
> called SpinCount.
Not quite - from the documentation for the API call
InitializeCriticalSectionAndSpinCount (which arrived with NT4SP3 and Win98),
we get:
"The spin count is useful for critical sections of short duration that can
experience high levels of contention. Consider a worst-case scenario, in
which an application on an SMP system has two or three threads constantly
allocating and releasing memory from the heap. The application serializes
the heap with a critical section. In the worst-case scenario, contention
for the critical section is constant, and each thread makes an expensive
call to the WaitForSingleObject function. However, if the spin count is
set properly, the calling thread will not immediately call
WaitForSingleObject when contention occurs. Instead, the calling thread
can acquire ownership of the critical section if it is released during the
spin operation.
You can improve performance significantly by choosing a small spin count
for a critical section of short duration. The heap manager uses a spin
count of roughly 4000 for its per-heap critical sections. This gives great
performance and scalability in almost all worst-case scenarios."
As I read it, a Win32 critical section will spin for a determined time
before executing the Wait. So it's actually half-and-half :)
Regards,
Andy
-- Andy Sawyer, Technical Director, Sufficiently Advanced Technology Ltd. mailto:andys_at_[hidden] ICQ:14417938 http://www.morebhp.com Mobile: (+44)7970 299892 [Voice/SMS] (+44)7970 523053 [Fax] "Any technology distinguishable from magic is insufficiently advanced"
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk