问题描述
请向我解释更多合同.我不知道ReentrantReadWriteLock
中包含的两个锁是否以某种方式相关?还是这些只是两个普通锁的捆绑?
Please explain me more the contract. I can't figure out if two locks contained in ReentrantReadWriteLock
somehow related? Or these are just a bundle of two normal locks?
推荐答案
如果线程正在等待读锁,则共享该锁,但是当线程想要获取写锁时,仅允许该线程进行互斥访问.
If threads are waiting Read Lock it is shared but when thread wants to acquire write lock only that thread is allowed the access same as mutual exclusion.
因此允许任何一种操作.if lock is held by readers and thread request write lock no more readers are allowed to acquire read lock until thread which has acquired write lock release it
.
So either one of operation is allowed .if lock is held by readers and thread request write lock no more readers are allowed to acquire read lock until thread which has acquired write lock release it
.
这篇关于ReentrantReadWriteLock中的读写锁是否以某种方式相关?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!