My understanding of the RentrantReadWriteLock is that it allows many reads at the same time but only one write.
When we try to acquire a read lock the doc states
Acquires the read lock if the write lock is not held by another thread and returns immediately.
If the write lock is held by another thread then the current thread becomes disabled
for thread scheduling purposes and lies dormant until the read lock has been acquired.
what does held
here mean?
- Another thread has requested a write lock and is executed than write?
or
- The above and the case when another thread has requested a write lock but is waiting to get it.
Because when a write lock is requested it is not granted if
- Someone else has a write lock
- Somebody else has a read lock
From write lock doc:
Acquires the write lock if neither the read nor write lock are held by another
thread and returns immediately, setting the write lock hold count to one.
...
If the lock is held by another thread then the current thread becomes
disabled for thread scheduling purposes and lies dormant until the write lock has
been acquired, at which time the write lock hold count is set to one.
So when a thread is waiting for a write lock after requesting it, I just want to get an idea of subsequent behaviour of invocations for read locks. Do they make the request for the write lock wait even longer or not?