Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the MSDN example usage of ReaderWriterLockSlim contain deadlock risk?

I'm using a ReaderWriterLockSlim to protect access to the cache on my ASP.NET application. MSDN has examples of using the lock. However this article http://www.nobletech.co.uk/Articles/ReaderWriterLockMgr.aspx has me worried about deadlocks. Is this really a risk? Should the MSDN documentation mention this?

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();
    }
}
like image 498
Andrew Davey Avatar asked Dec 31 '25 16:12

Andrew Davey


1 Answers

Sorry, i miss read earlier,

Does this attribute not specify that?

[HostProtectionAttribute(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
like image 131
Adriaan Stander Avatar answered Jan 03 '26 07:01

Adriaan Stander



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!