In the await method of AQS (AbstractQueuedSynchronizer):
I want to know the meaning of while in while (!isOnSyncQueue(node)) {
I think that if this node is woken up normally (without being interrupted), It will definitely be moved to the sync queue after the signal method is executed by another thread, and then woken up by executing the unlock method in another thread.
So there could be a situation where a node is waking up normally, but not in the sync queue? If that's not possible, I think if should be used here instead of while
public final void await() throws InterruptedException {
if (Thread.interrupted())
throw new InterruptedException();
Node node = addConditionWaiter();
int savedState = fullyRelease(node);
int interruptMode = 0;
while (!isOnSyncQueue(node)) {
LockSupport.park(this);
if ((interruptMode = checkInterruptWhileWaiting(node)) != 0)
break;
}
if (acquireQueued(node, savedState) && interruptMode != THROW_IE)
interruptMode = REINTERRUPT;
if (node.nextWaiter != null) // clean up if cancelled
unlinkCancelledWaiters();
if (interruptMode != 0)
reportInterruptAfterWait(interruptMode);
}