Replace critical section with SRW lock

前端 未结 1 696
谎友^
谎友^ 2021-02-08 01:01

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 eq

相关标签:
1条回答
  • 2021-02-08 01:24

    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.

    Kenny Kerr's article describes a little about how both are implemented internally.

    0 讨论(0)
提交回复
热议问题