>Someone correct me if I'm wrong, but I get the impression that in
>order for a synchronization construct to be MP safe it must eventually
>reduce to some kind of busy-wait test and set hardware level loop.
All high-level sync objects in Windows reduce to KiDispatcherLock spinlock :-)
In Win7, this was changed to several lock-free atomic operations (Win7 has lock-free dispatcher).
>this is true, I don't see much difference between a Mutex and a
>Spinlock, except that the Mutex gives the system a chance not to spin
Correct. When the thread stops on mutex, KiDispatcherLock is taken and, under this lock, the thread is marked as "waiting" and another thread is chosen for execution.
When the thread stops on spinlock, the whole CPU is stalled.
>Talking about fast mutexes, I have had plenty of trouble trying to
>issue driver log messages to my log file from inside fast mutexes -
>caveat emptor.
Correct, ZwXxx do not work at APC_LEVEL, but I would use a producer/consumer logic and logging work item for logging, not direct ZwWriteFile.
>One idea is to synchronize through a homegrown macro or a C++ class -
Yes. Beware of C++ exceptions in the kernel though and note that you must wrap _any_ function call which can fail to the exception. Without this, the C++ "locker" object is useless.
--
Maxim S. Shatskih
Windows DDK MVP
http://www.storagecraft.com