用SRW锁替换关键部分 [英] Replace critical section with SRW lock

查看:84
本文介绍了用SRW锁替换关键部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果该应用程序针对Windows Vista或更高版本,我们是否可以替换所有关键部分"rel =" noreferrer> SRW锁?由于关键部分是互斥的,因此对于使用而言,它等效于互斥模式下的SRW锁,对吗?根据MSDN,SRW已针对速度和空间进行了优化.这样做有什么缺点吗?我不确定Microsoft如何在内部实现CS和SRW.

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.

谢谢!

推荐答案

请参阅Joe Duffy的书"Windows上的并行编程",第289页.

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

您的问题的简短答案是几乎".递归获取的CRITICAL_SECTION的语义与SRWL的语义不同.如果您的程序利用了Win32关键部分的这些特性,那么您将无法轻松地批量切换到SRWL.但是,您可以将SRWL包装在包装器中,以提供类似CS的语义,但是这样做有很多微妙之处,因此,如果您依赖于CS行为,那么最好还是坚持使用CS.

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)的文章简要介绍了两者如何在内部实现

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

这篇关于用SRW锁替换关键部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆