3

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();
    }
}
Andrew Davey
  • 5,441
  • 3
  • 43
  • 57

1 Answers1

2

Sorry, i miss read earlier,

Does this attribute not specify that?

[HostProtectionAttribute(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
Adriaan Stander
  • 162,879
  • 31
  • 289
  • 284
  • 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 Sep 21 '09 at 14:32
  • 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 – Adriaan Stander Sep 21 '09 at 15:04