views:

39

answers:

1

If the application is targeted on Windows Vista or later, could we replace all critical sections with SRW locks? Since critical section is mutually exclusive, for usage it is equivalent to SRW locks in exclusive mode, right? According to MSDN, SRW is optimized both for speed and space. Is there any drawback for doing this? I'm not sure how CS and SRW are implemented internally by Microsoft.

Thanks!

A: 

See Joe Duffy's book "Concurrent Programming on Windows", pg 289.

The short answer to your question is "almost". There are semantics with recursively acquired CRITICAL_SECTION's that are different for SRWL's. If your program took advantage of these characteristics of Win32's critical sections, then you can't wholesale switch to SRWL easily. You could, however, wrap an SRWL in a wrapper to provide CS like semantics, but there are a bunch of subtleties in doing so, so you are better off sticking to CS's if you are depending on such behavior.

Mark Oskin, Chief Technology Officer Corensic, http://corensic.com

Mark oskin