Re: Critical section vs. other sync mechanisms
"ext" <ext@comcast.com> wrote in message
news:evE5Y4sXHHA.1388@TK2MSFTNGP05.phx.gbl
Isn't Critical section a kernel object? If no, why isn't it like other
kernel objects for sync?
Critical section is a combination of a spinlock and an event. Spinlock
is just an integer counter, updated with interlocked instructions. Event
is of course a kernel object. A critical section code would try to
acquire the lock without transitioning to kernel mode if possible, but
if one thread holds the section for a long time, others would wait on an
event (thus transitioning to kernel mode).
Is it possible to sync without help from kernel at all?
You can write your own spinlock. Note that a thread "waiting" on a
spinlock keeps the CPU 100% busy. You don't want to do that for a long
period of time. That's why a critical section is the best of both
worlds.
See also InitializeCriticalSectionAndSpinCount. By setting initial spin
count to a very high value, you can make sure the section always spins
and never waits on event handle.
What's "Kernel Level Critical Sections"? What's the differences
between them and User Level Critical Sections?
I'm not familiar with the term. Where did you find it? It doesn't seem
to be mentioned anywhere in Microsoft's documentation.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925