并发编程中的屏障算法解析
1. 静态树屏障
在并发编程中,之前的屏障算法存在一些问题,比如简单屏障和反转感知屏障存在争用问题,组合树屏障存在通信过多的问题。而静态树屏障则提供了一种既能实现静态布局又能降低争用的解决方案。
1.1 内部节点类
private class Node {
AtomicInteger count;
Node parent;
volatile boolean sense;
public Node() {
sense = false;
parent = null;
count = new AtomicInteger(radix);
}
public Node(Node myParent) {
this();
parent = myParent;
}
public void await() {
boolean mySense = threadSense.get();
int position = count.getAndDecrement();
if (position == 1) { // I’m last
if (parent != null) { // Am I root?
parent.await();
}
count.set(radix);
sense = mySense;
超级会员免费看
订阅专栏 解锁全文
1171

被折叠的 条评论
为什么被折叠?



