【问题标题】:Does the MSDN example usage of ReaderWriterLockSlim contain deadlock risk?ReaderWriterLockSlim 的 MSDN 示例用法是否包含死锁风险?
【发布时间】:2010-11-30 01:55:03
【问题描述】:

我正在使用 ReaderWriterLockSlim 来保护对 ASP.NET 应用程序上缓存的访问。 MSDN 有使用锁的例子。然而这篇文章http://www.nobletech.co.uk/Articles/ReaderWriterLockMgr.aspx 让我担心死锁。这真的有风险吗? MSDN 文档应该提到这一点吗?

public string Read(int key)
{
    cacheLock.EnterReadLock();
    // What if thread abort happens here before getting into the try block?!
    try
    {
        return innerCache[key];
    }
    finally
    {
        cacheLock.ExitReadLock();
    }
}

【问题讨论】:

    标签: asp.net thread-safety deadlock readerwriterlockslim


    【解决方案1】:

    对不起,我错过了之前的阅读,

    这个属性没有指定吗?

    [HostProtectionAttribute(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
    

    【讨论】:

    • 那么我是否需要补偿潜在的中止(在我的 ASP.NET 应用程序的上下文中)?最安全的方法是什么?
    • 您提供的参考文章似乎很可靠。本文还扩展了功能vijay.screamingpens.com/archive/2008/08/08/…
    猜你喜欢
    • 2011-05-08
    • 1970-01-01
    • 1970-01-01
    • 2012-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多