readerwriterlockslim

Is ReaderWriterLockSlim the right choice?

喜欢而已 提交于 2019-12-01 08:24:32
I'm writing a global error handler/logger for applications running in Windows Azure. When an error occurs in the application, a number of operations are performed that need to happen atomically. I need to prevent an error from being logged until the previous one has completed. Meanwhile, I want reads of the logs to occur as needed. My initial thought was using a Monitor/lock and lock only the error writes. That way the reads aren't inhibited at all. I was wondering though whether a ReaderWriterLockSlim would be more appropriate. I can't say I truly understand the value between one approach vs.

Is ReaderWriterLockSlim the right choice?

纵饮孤独 提交于 2019-12-01 07:02:24
问题 I'm writing a global error handler/logger for applications running in Windows Azure. When an error occurs in the application, a number of operations are performed that need to happen atomically. I need to prevent an error from being logged until the previous one has completed. Meanwhile, I want reads of the logs to occur as needed. My initial thought was using a Monitor/lock and lock only the error writes. That way the reads aren't inhibited at all. I was wondering though whether a

ReaderWriterLockSlim.EnterUpgradeableReadLock() Always A Deadlock?

大兔子大兔子 提交于 2019-11-29 15:14:20
问题 I'm very familiar with ReaderWriterLockSlim but tried my hand at implementing EnterUpgradeableReadLock() recently in a class... Soon after I realized that this is almost certainly a guaranteed deadlock when 2 or more threads run the code: Thread A --> enter upgradeable read lock Thread B --> enter upgradeable read lock Thread A --> tries to enter write lock, blocks for B to leave read Thread B --> tries to enter write lock, blocks for A to leave read Thread A --> waiting for B to exit read