readerwriterlockslim

Determining which method is holding a ReaderWriterLockSlim WriteLock

…衆ロ難τιáo~ 提交于 2021-01-27 07:40:28
问题 Currently I am analyzing a dump with WinDbg. I ran following commands (following Tess' incredible walkthrough): ~* e !clrstack Which listed me all stacks of all threads. There are 300 running threads with more or less the same stack, so I am just printing the stack of one here ... OS Thread Id: 0x107c (166) Child SP IP Call Site 2bc1e654 77c1015d [HelperMethodFrame_1OBJ: 2bc1e654] System.Threading.WaitHandle.WaitOneNative(System.Runtime.InteropServices.SafeHandle, UInt32, Boolean, Boolean)

Determining which method is holding a ReaderWriterLockSlim WriteLock

陌路散爱 提交于 2021-01-27 07:35:26
问题 Currently I am analyzing a dump with WinDbg. I ran following commands (following Tess' incredible walkthrough): ~* e !clrstack Which listed me all stacks of all threads. There are 300 running threads with more or less the same stack, so I am just printing the stack of one here ... OS Thread Id: 0x107c (166) Child SP IP Call Site 2bc1e654 77c1015d [HelperMethodFrame_1OBJ: 2bc1e654] System.Threading.WaitHandle.WaitOneNative(System.Runtime.InteropServices.SafeHandle, UInt32, Boolean, Boolean)

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

主宰稳场 提交于 2019-12-22 09:22:07
问题 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 become aware of ReaderWriterLockSlim... From the docs, I believe that there can only be one thread in "upgradeable mode" at any one time. In a situation where the

How to make windows slim read writer lock fair?

别等时光非礼了梦想. 提交于 2019-12-12 22:38:14
问题 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 possibility to make the windows rw-lock with some workaround fair or fifo? If not, in which scenarios would you use the windows slim rw-lock? 回答1: It is unlikely you can change the slim lock itself to be fair, especially since the documentation

Again double-checked locking and C#

为君一笑 提交于 2019-12-10 14:29:16
问题 Recently I have been refactoring some of my C# code and I found a few double-checked locking practices taking place. I didn't know it was a bad practice back then and I really want to get rid of it. The problem is that I have a class that should be lazily initialized and frequently accessed by lots of threads. I also do not want to move the initialization to a static initializer, because I am planning to use a weak reference to keep the initialized object from staying too long in the memory.

Is locking access to a bool required or is it Overkill

戏子无情 提交于 2019-12-09 08:39:38
问题 I have a class that is designed primarily as a POCO class, with various Threads and Tasks could read its values, and only others only occasionally updating these values. This seems to be an ideal scenario for ReaderWriterLockSlim. The question is, in the class, if the property that needs to be thread-safe, if the property is a bool, is that overkill? what happens if it is an int? DateTime? public class MyClass { private bool _theValue = false; private ReaderWriterLockSlim _theValueLock = new

What are the real downsides of using ReaderWriterLock

拈花ヽ惹草 提交于 2019-12-08 17:45:25
问题 We have project targeted .NET 2.0 RTM (yes, it should be .NET 2.0 RTM, we have some orthodox clients). And I'm just wondering what are the downsides of ReaderWriterLock? Why is it so bad that everyone tell "don't use it, try to use something else like lock statement"? If we could use .NET 3.5, I would definitely use ReaderWriterLockSlim, but with ReaderWriterLock I'm a little scary with all these warning coming from everywhere. Does anybody measured performance or whatever? If there are some

Is it completely safe to use pattern of ReaderWriterLockSlim.EnterXXX() with consequent try-finally clause

巧了我就是萌 提交于 2019-12-05 22:55:44
问题 MSDN Documentation and many examples of using ReaderWriterLockSlim class recommends using the following pattern: cacheLock.EnterWriteLock(); try { //Do something } finally { cacheLock.ExitWriteLock(); } But I'm curious if it's completely safe. Is it possible that some exception will happen after lock is acquired, but before the try statement so that lock is stuck in the locked state? The most obvious candidate is ThreadAbortException . I understand that probability of this situation is

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

女生的网名这么多〃 提交于 2019-12-05 19:49:49
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 become aware of ReaderWriterLockSlim ... From the docs, I believe that there can only be one thread in "upgradeable mode" at any one time. In a situation where the only access I'm using is EnterUpgradeableReadLock() (which is appropriate for my scenario) then is

Is it completely safe to use pattern of ReaderWriterLockSlim.EnterXXX() with consequent try-finally clause

不问归期 提交于 2019-12-04 05:55:58
MSDN Documentation and many examples of using ReaderWriterLockSlim class recommends using the following pattern: cacheLock.EnterWriteLock(); try { //Do something } finally { cacheLock.ExitWriteLock(); } But I'm curious if it's completely safe. Is it possible that some exception will happen after lock is acquired, but before the try statement so that lock is stuck in the locked state? The most obvious candidate is ThreadAbortException . I understand that probability of this situation is extreemely small, but the consequences are extreemely bad - so I think it worth thinking about it. I don't