提交 60d85c68 编写于 作者: D dl

6803402: Race condition in AbstractQueuedSynchronizer

Summary: Read fields in reverse initialization order
Reviewed-by: martin
上级 5cbea3f6
......@@ -1222,8 +1222,10 @@ public abstract class AbstractQueuedLongSynchronizer
// The correctness of this depends on head being initialized
// before tail and on head.next being accurate if the current
// thread is first in queue.
Node h, s;
return (h = head) != tail &&
Node t = tail; // Read fields in reverse initialization order
Node h = head;
Node s;
return h != t &&
((s = h.next) == null || s.thread != Thread.currentThread());
}
......
......@@ -1445,8 +1445,10 @@ public abstract class AbstractQueuedSynchronizer
// The correctness of this depends on head being initialized
// before tail and on head.next being accurate if the current
// thread is first in queue.
Node h, s;
return (h = head) != tail &&
Node t = tail; // Read fields in reverse initialization order
Node h = head;
Node s;
return h != t &&
((s = h.next) == null || s.thread != Thread.currentThread());
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册