ReaderWriterLockSlim

兼容模式

                    read      upgradable     write

read              true          true            false

upgradable     true          false           false

write              false         false           false

 

这个矩阵是对称的。 read -> upgradable -> write 锁定级别依次提高。

所谓的锁定升级,是指在不释放已持有的较低级别的锁的前提下,再去获取更高级别的锁。

关于upgradable这个级别,MSDN上说:

Only one thread can enter upgradeable mode at any given time. If a thread is in upgradeable mode, and there are no threads waiting to enter write mode, any number of other threads can enter read mode, even if there are threads waiting to enter upgradeable mode. 在任意时刻仅有一个线程可以进入可升级读模式。如果有一个线程处于可升级读模式,并且没有任何线程等待进入写模式,那么任意数量的线程可以进入读模式,即使有线程在等待进入可升级读模式。

If one or more threads are waiting to enter write mode, a thread that calls the EnterUpgradeableReadLock method blocks until those threads have either timed out or entered write mode and then exited from it. 如果一个或多个线程在等待进入写模式,那么试图进入可升级读模式的线程会被阻塞,直到等待进入写模式的线程全部退出或超时。

转载于:https://www.cnblogs.com/zhy2002/archive/2008/11/18/1335879.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值