views:

263

answers:

1

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();
    }
}
A: 

Sorry, i miss read earlier,

Does this attribute not specify that?

[HostProtectionAttribute(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
astander
So do I need to compensate for potential aborts (in the context of my ASP.NET app)? What is the safest way to do this?
Andrew Davey
The reference article you provided seems pretty solid. This article also extends the functionality http://vijay.screamingpens.com/archive/2008/08/08/readerwriterlockslim-extension-methods.aspx
astander