We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
由于公平锁需要关心队列的情况,得按照队列里的先后顺序来获取锁(会造成大量的线程上下文切换),而非公平锁则没有这个限制。
公平锁的阻塞是按节点顺序进行的,而唤醒也是按节点顺序进行的,为什么会造成大量的线程上下文的切换呢?我的理解是,公平锁的吞吐量不是很高。
final boolean acquireQueued(final Node node, int arg) { boolean failed = true; try { boolean interrupted = false; for (;;) { final Node p = node.predecessor(); if (p == head && tryAcquire(arg)) { setHead(node); p.next = null; // help GC failed = false; return interrupted; } if (shouldParkAfterFailedAcquire(p, node) && parkAndCheckInterrupt()) interrupted = true; } } finally { if (failed) cancelAcquire(node); } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
公平锁的阻塞是按节点顺序进行的,而唤醒也是按节点顺序进行的,为什么会造成大量的线程上下文的切换呢?我的理解是,公平锁的吞吐量不是很高。
The text was updated successfully, but these errors were encountered: