ReaderWriterLockSlim is a class in Microsoft .NET framework which represents a lock that is used to manage access to a resource, allowing multiple threads for reading or exclusive access for writing.
Questions tagged [readerwriterlockslim]
79 questions
0
votes
0 answers
Serializing an object to a file via System.Text.Json.Serialization appears to break ReaderWriterLockSlim
I have a requirement for a simple List<> to be used in an async environment and be concurrent. The list does only has a hand full of methods and is not a full implementation of IList. I have used the ReaderWriterLockSlim class to enable a locking…

Muz
- 289
- 1
- 3
- 11
0
votes
1 answer
Intelocked.Exchange instead of ReaderWriterLockSlim
In a multithreaded application, I have a Dictionary that is accessed by multiple threads for gettinng the value for a specific key. There is also a mechanism using Quartz.Net to update this dictionary.
I am trying to find the best way to make the…

fdhsdrdark
- 144
- 1
- 13
0
votes
1 answer
Questions about ReaderWriterLockSlim. I use readerwriterlockslim to read and write, but only show write at last in console. Why?
this is code:
class program
{
static ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim();
static void Main(string[] args)
{
for (int i = 0; i < 2; i++)
{
Task.Factory.StartNew(Read);
}
for…

jzian
- 23
- 5
0
votes
1 answer
How to make group of operations atomic without using Lock
I have a state variable whose fields of interest are thread-safe and kept fresh using a ReaderWriterLockSlim.I have fine-grained the access to all fields since i use them somewhere else separately.
While for individual access of fields it works fine…

Bercovici Adrian
- 8,794
- 17
- 73
- 152
0
votes
0 answers
C# Best Practice used for application multithreading log building cross-form instance
I'm building a UI which consists of one main Form with possible instances of additional forms and custom classes. What I'm still missing is a consistent way of logging errors. So what I do is I created try-catch blocks around all code that could…

AGI_rev
- 129
- 10
0
votes
0 answers
How to set a reader-writer lock for a specific segment of code?
I need to lock a specific section of my code and the problem is as follows:
I must allow multiple read threads and single write thread to the section something like:
get readlock()
{
if(s==1)
get writelock()
or else
continue with read…

Saranya Krishnan
- 11
- 1
0
votes
1 answer
using (IDisposable) vs. class field - correct usage of ReaderWriterLockSlim
In a FileWriter class that will be used by different threads, I currently use a ReaderWriterLockSlim to prevent errors occurring when two threads try to write to the file at the same time like this:
(1)
public class FileWriter
{
private…

Thomas Flinkow
- 4,845
- 5
- 29
- 65
0
votes
1 answer
ASP.NET Caching lock mechanisme
Using .NET 3.5. I'm storing customer objects in the cache using ReaderWriterLockSlim. The problem is that when a user from Customer A is doing an action that will result in a update to the customer object in the cache; the EnterWriteLock() will…

Mikael
- 1
0
votes
0 answers
safe thread map/hashtable using AcquireSRWLock
I am providing a thin wrapper around a non-thread safe map using AcquireSRWLockShared and AcquireSRWLockExclusive Windows APIs. Essentially, lookup related methods are taking a read lock and "set" related methods are taking a write lock -- simple…

alernerdev
- 2,014
- 3
- 19
- 35
0
votes
2 answers
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…

Ian Hannah
- 1
- 2
0
votes
2 answers
Using ReaderWriterLockSlim for Opposite of readers-writer
I need to allow multiple writers/single-reader at the same time.
I have found ReaderWriterLockSlim class but I have a problem with the naming. I need to use EnterReadLock() for allowing writer to write and EnterWriteLock() for allowing reader to…

L_D
- 11
- 4
0
votes
1 answer
Multiple ReaderWriterLockSlim on a Resource
ReaderWriterLockSlim allows a lock that is used to manage access to a resource, allowing multiple threads for reading or exclusive access for writing. currently we have the following code in place:
public ReaderWriterLockSlim protDataA = new…

LetsKickSomeAss in .net
- 536
- 1
- 8
- 22
0
votes
1 answer
Class for mantain a thread safe cache
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…

vtortola
- 34,709
- 29
- 161
- 263
0
votes
2 answers
Best practices for not the leave opened locks
Albahari Threading section about ReaderWriterLockSlim shows usage of this locker. But there is no any try-catch and finally blocks against exceptional cases.
Why he hasn't used exception handling to not leave opened locks ? At below example, write…

Freshblood
- 6,285
- 10
- 59
- 96
0
votes
0 answers
ReaderWriter Lock, My code just gives exceptions
I'm trying to implement the Reader Writer Problem .. I don't know what is wrong with it?
can any one help me figure out why?
...................................................
package readerWriterController;
import java.util.ArrayList;
import…

YaoMing
- 1
- 1