1

如何知道 ReaderWriterLockSlim 当前是否被另一个线程写锁定?

ReaderWriterLockSlim rwls = new ReaderWriterLockSlim()
var i = rwls.CurrentReadCount; 
// count of reading threads (but unfortunately there's no CurrentWriteCount property)
var j = rwls.IsWriteLockHeld; 
// check if current thread is holding the lock (limited to current thread)

/* none of above can do it */

是的,我可以调用 rwls.TryEnterWriteLock(1) 来检查它是否被写锁定,但这会降低性能

有没有直接的方法来获得写锁定状态?

4

0 回答 0