无法获取 Quasar ReenterantReadWriteLock

Quasar ReenterantReadWriteLock can't be acquired

我有一个 lock:

private ReentrantReadWriteLock requestWaitingLock;

我正在 Fiber:

中执行这个块
System.out.println(requestWaitingLock.isWriteLocked());
System.out.println(requestWaitingLock.getReadHoldCount());
requestWaitingLock.writeLock().lock();
System.out.println("write lock acquired");

那是因为在文档中它说:

public void lock()
Acquires the write lock if neither the read nor write lock are held by another strand and returns immediately, setting the write lock hold count to one.
If the current strand already holds the write lock then the hold count is incremented by one and the method returns immediately.
If the lock is held by another strand then the current strand becomes disabled for strand scheduling purposes and lies dormant until the write lock has been acquired, at which time the write lock hold count is set to one.

所以我得到了这个输出:

false
0

这意味着读锁和写锁都没有被任何 Strand 持有。那为什么我的 Fiber 被屏蔽了?

编辑。我很确定每个获取此锁的纤程都会释放它,因此其他纤程不可能无限地获取它。

您似乎调用了不正确的方法来检查 reader 锁:

  • getReadHoldCount - 仅针对当前线程
  • getReadLockCount - 对于系统中的所有线程