Slim Reader Writer Locks

In a recent internal thread, there's been some good discussion about the new Slim Reader Writer locks in Vista. See the SRWLockXXX functions for details.

A brief synopis of the key points about these locks:

Since XP, there's a new intra-process synchronization mechanism in the kernel called "keyed events". Basically you register a wait on a PVOID value, and you'll block until another thread in the same process signals with the same PVOID value. An MSN search on "keyed events" and "kernel" brings up a few bits of information.

 

This lets you build user mode synchronization primitives which have no extra kernel mode costs beyond the memory used for the synchronization primitive.

 

EnterCriticalSection() shouldn't fail any more - In low memory conditions, it falls back to using a keyed event.

 

SRW locks are lighter than critical sections. It's very fast to create & destroy them, and they use less memory. Consider using them in place of critical sections when it makes sense.

 

SRW locks don't support recursion semantics like critical sections do, and it's harder to debug threading issues, as the owner isn't tracked.

 

Key point: These are just the highlights of the discussion. I only learned about these locks a few days ago, so claim no expert status.