readerwriterlockslim

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) {...

Is there a safe way to use ReaderWriterLockSlim within ASP.NET?

Joe Duffy's article about ReaderWriterLockSlim does not fill me with confidence! http://www.bluebytesoftware.com/blog/2007/02/07/IntroducingTheNewReaderWriterLockSlimInOrcas.aspx How can I safely use ReaderWriterLockSlim in ASP.NET? ...

Optimized ReaderWriterLock Read Access (C#)

So it's my understanding that on a ReaderWriterLock (or ReaderWriterLockSlim more specifically), both the read and write need acquire a mutex to take the lock. I'd like to optimize the read access of the lock, such that if there are no writes pending, no lock need be acquired. (And I'm willing to sacrifice the performance of writes, add ...

ReaderWriterLockSection: A bad idea?

In writing some threaded code, I've been using the ReaderWriterLockSlim class to handle synchronized access to variables. Doing this, I noticed I was always writing try-finally blocks, the same for each method and property. Seeing an opportunity to avoid repeating myself and encapsulate this behaviour I built a class, ReaderWriterLockSe...

Class for mantain a thread safe cache

Hi, I'm developing a thread safe class that I'll use as cache, it should work in .NET and Mono. The items have a time to live, and every time that a object is retrieved, its time to live is refreshed. Each time that I add a item, the timestamp is added to another collection that holds the same keys. A timer raises the method that look...

Is ReaderWriterLockSlim.EnterUpgradeableReadLock() essentially the same as Monitor.Enter()?

So I have a situation where I may have many, many reads and only the occasional write to a resource shared between multiple threads. A long time ago I read about ReaderWriterLock, and have read about ReaderWriterGate which attempts to mitigate the issue where many writes coming in trump reads and hurt performance. However, now I've bec...

Synchronize Read Write Collection in .NET

I have an object which holds a collection of items. I want to be able to add items to the collection through an AddItem method and also to go through all of the items in the collection. My object must be thread safe. I am using a ReaderWriterLockSlim to assure proper synchronization. How should I synchronize the GoThroughAllItems method?...

Speed issues with ReaderWriterLockSlim and Garbage Collection

I have an example piece of code the illustrates issues in my code when GC.Collect is carried out on a class having a ReaderWriterLockSlim member variable. The GC.Collect takes between 2 and 3 seconds to run. I need to carry out GC at regular intervals because my applicaton is extremely memory intensive. namespace WpfApplication12 { ...