我正在使用 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();
}
}