Re: Critical Sections, Thread Priorities, and Pre-emption
- From: "Kevin" <kevin11@xxxxxxxxxxx>
- Date: Mon, 26 Mar 2007 12:13:44 -0700
"m" <m@xxx> wrote in message news:uyoLvqkbHHA.2552@xxxxxxxxxxxxxxxxxxxxxxx
I would suggest that in the case that you mention, a CS is still better.
If you set the spin count to zero, then you get the same benefit of a Mutex
in cases where there is contention (with a tiny overhead) but in cases
where there is no contention, then you avoid the UM-KM transitions.
True. The tiny overhead in the case of no-contention is a big win over
always transitioning to kernel mode to take an unowned mutex.
There originally was no documented way of intializing the spincount, and
still it is not documented as supported under Win9x -- probably a non-issue
for the OPs case, but which is the basis for my opinions.
There are situations where a Mutex is more desirable then a CS within a
single process, but they usually have more to do with compatibility than
performance. ie extending an existing app, integrating existing apps into
a single app, or working with a broken sync design, that can't easily be
changed, that causes constant contention between many threads.
True.
The other reason to use a Mutex over a CS is to be notified when a thread
abandons the lock.
Of course this is why you must tune the spin count for all critical
sections. This tuning is also hardware dependent so depending on what you
are writing (a desktop app versus an embedded server etc.) the type of
optimizations that are effective will vary. Only the OP can know what is
appropriate to his application.
Yes, dedicated hardware with a known process set is a prime candidate for
such tuning. Software meant to run on end-user computers suffers the
typical "if everyone raised their priority, no one's priority is raised".
BTW: I don't know where the decision to spin or not is implemented, but
since it must be in UM, I doubt that ntoskrnl.exe has anything to do with
it - likely kernel32.dll?
You have a point there. My knowledge must be stale, or incomplete, or more
likely: both. Maybe even just plain wrong!! Habits get born from necessity
and are hard to break. So, I appreciate your corrections to my statements.
.
- References:
- Prev by Date: table of waitable timers - utility to view?
- Next by Date: Re: Protecting process
- Previous by thread: Re: Critical Sections, Thread Priorities, and Pre-emption
- Next by thread: Re: Critical Sections, Thread Priorities, and Pre-emption
- Index(es):
Relevant Pages
|