b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

链表 结构 解读 Java 并发队列 BlockingQueue(8)

电脑杂谈  发布时间:2018-02-21 23:42:01  来源:网络整理

clean(t, s);

return null;

}

if (!s.isOffList()) { // not already unlinked

advanceHead(t, s); // unlink if head

if (x != null) // and forget fields

s.item = s;

s.waiter = null;

}

return (x != null) ? x : e;

// 这里的 else 分支就是上面说的第二种情况,有相应的读或写相匹配的情况

} else { // complementary-mode

QNode m = h.next; // node to fulfill

if (t != tail || m == null || h != head)

continue; // inconsistent read

Object x = m.item;

if (isData == (x != null) || // m already fulfilled

x == m || // m cancelled

!m.casItem(x, e)) { // lost CAS

advanceHead(h, m); // dequeue and retry

continue;

}

advanceHead(h, m); // successfully fulfilled

LockSupport.unpark(m.waiter);

return (x != null) ? x : e;

}

}

}

void advanceTail(QNode t, QNode nt) {

if (tail == t)

UNSAFE.compareAndSwapObject(this, tailOffset, t, nt);

}

// 自旋或阻塞,直到满足条件,这个方法返回

Object awaitFulfill(QNode s, Object e, boolean timed, long nanos) {

long lastTime = timed ? System.nanoTime() : 0;

Thread w = Thread.currentThread();

// 判断需要自旋的次数,

int spins = ((head.next == s) ?

(timed ? maxTimedSpins : maxUntimedSpins) : 0);

for (;;) {

// 如果被中断了,那么取消这个节点

if (w.isInterrupted())

// 就是将当前节点 s 中的 item 属性设置为 this

s.tryCancel(e);

Object x = s.item;

// 这里是这个方法的唯一的出口

if (x != e)

return x;

// 如果需要,检测是否超时

if (timed) {

long now = System.nanoTime();

nanos -= now - lastTime;

lastTime = now;

if (nanos <= 0) {

s.tryCancel(e);

continue;

}

}

if (spins > 0)

--spins;

// 如果自旋达到了最大的次数,那么检测

else if (s.waiter == null)

s.waiter = w;

// 如果自旋到了最大的次数,那么线程挂起,等待唤醒

else if (!timed)


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-87792-8.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...