Questions tagged [readerwriterlockslim]

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.

79 questions
1
vote
0 answers

ReaderWriterLockSlim.EnterReadLock before try block, is there a reason?

A lot of examples for the ReaderWriterLockSlim are written this way: public string Read(int key) { cacheLock.EnterReadLock(); // is there a reason for this try { return innerCache[key]; } finally { …
xdroid81
  • 11
  • 2
1
vote
0 answers

ReaderWriterLockSlim gets stuck on TryEnterReadLock

I have following code: private static readonly ReaderWriterLockSlim Locker = new ReaderWriterLockSlim(); private void TryGetReadLock() { if (!Locker.IsWriteLockHeld && !Locker.IsReadLockHeld) …
Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
1
vote
2 answers

How can I reduce locking for readers in generic cached repository?

I have created a generic CachedRepository that looks like the following: public class CachedRepository : ICachedRepository, IRepository where T : BaseModel, new() { private static readonly Lock TypeLock = new Lock(); …
Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
1
vote
2 answers

How to make windows slim read writer lock fair?

i found out that windows implemented a slim reader-writer-lock (see https://msdn.microsoft.com/en-us/library/windows/desktop/aa904937%28v=vs.85%29.aspx ). Unfortunately (for me) this rw-lock is neither fifo nor is it fair (in any sense). Is there a…
user1235183
  • 3,002
  • 1
  • 27
  • 66
1
vote
0 answers

How to know if a ReaderWriterLockSlim is currently write-locked by another thread?

How to know if a ReaderWriterLockSlim is currently write-locked by another thread? ReaderWriterLockSlim rwls = new ReaderWriterLockSlim() var i = rwls.CurrentReadCount; // count of reading threads (but unfortunately there's no CurrentWriteCount…
ineztia
  • 815
  • 1
  • 13
  • 29
1
vote
1 answer

(C#) make auto GC possible for Dictionary

I maintained a dictionary of ReaderWriterLockSlim objects for resource access:(sample code is ugly here, just makes you understand my purpose) static ConcurrentDictionary rwResourceLocks = …
ineztia
  • 815
  • 1
  • 13
  • 29
1
vote
1 answer

ReaderWriterLockSlim throws LockRecursionException with Socket.BeginReceive

Given the simple socket client class below, connect it to a TCP server (I use SocketTest3, freely available online). Then disconnect the server and wait for a bit. You should get a LockRecursionException. using System; using…
relatively_random
  • 4,505
  • 1
  • 26
  • 48
1
vote
1 answer

"Reimplementing" (cloning) ReaderWriterLockSlim

We have several full lock-s in our web application that could be more performant if they were replaced with read-writer locks - even with the additional overhead of the RW lock, our code would be more parallel. Unfortunately, I cannot use…
xxbbcc
  • 16,930
  • 5
  • 50
  • 83
1
vote
2 answers

Multithreading Update with ReaderWriterLockSlim

I think I made a huge error when I first started designing my game and would give you some or even all of my code but it is just too complex. So please bear with me. Now that I get to the more advanced stages of my design I am running into major…
user2888973
  • 583
  • 3
  • 15
1
vote
2 answers

Optimized ReaderWriterLock Read Access

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…
Gene
  • 1,587
  • 4
  • 18
  • 38
1
vote
1 answer

ReaderWriterLockSlim missing from System::Threading namespace with C++/CLI

I recently installed Visual Studio 2012 and tried recompiling an existing project which is a mixed mode C++ application with a little C++/cli used to access a .net assembly required by the app. Part of the C++/CLI implementation uses a…
1
vote
1 answer

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

Joe Duffy's article about ReaderWriterLockSlim does not fill me with confidence! Introducing the new ReaderWriterLockSlim in Orcas The lock is not robust to asynchronous exceptions such as thread aborts and out of memory conditions. If one of…
Andrew Davey
  • 5,441
  • 3
  • 43
  • 57
0
votes
0 answers

Xamarin NULL character in Read/Write shared file

I have a Xamarin Forms application running in Android 7.1, in which several objects have to concurrently write lines into a single shared file. So, I created the following class Log.cs, following the Microsoft documentation about the…
J.Doe
  • 133
  • 6
0
votes
0 answers

FileSystemWatcher group multiple files into one action lock issue

I'm using FileSystemWatcher to upload files to an Azure Blob and I ran into a problem when a bunch of files were created at the same time, resulting in connection issues as every file gets a new connection to the Azure storage account. I followed…
0
votes
1 answer

Dispose ReaderWriterLockSlim after ExitWriterLock

I have a function to clean up some objects as well as the ReaderWriterLockSlim. But I need the ReaderWriterLockSlim to lock as writer lock to prevent the other thread read the data while I am doing the clean up. ConcurrentDictionary