6803402: Race condition in AbstractQueuedSynchronizer

Read fields in reverse initialization order

Reviewed-by: martin
This commit is contained in:
Doug Lea 2009-02-24 14:01:45 -08:00
parent ee5c2301ec
commit ca6e1aecc3
2 changed files with 8 additions and 4 deletions

View File

@ -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());
}

View File

@ -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());
}