changeset 921:266358f13a6f

6803402: Race condition in AbstractQueuedSynchronizer Summary: Read fields in reverse initialization order Reviewed-by: martin
author dl
date Tue, 24 Feb 2009 14:01:45 -0800
parents dc237aecf7cf
children dde3fe2e8164
files src/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java src/share/classes/java/util/concurrent/locks/AbstractQueuedSynchronizer.java
diffstat 2 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java	Tue Feb 24 14:22:08 2009 +0000
+++ b/src/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java	Tue Feb 24 14:01:45 2009 -0800
@@ -1222,8 +1222,10 @@
         // 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());
     }
 
--- a/src/share/classes/java/util/concurrent/locks/AbstractQueuedSynchronizer.java	Tue Feb 24 14:22:08 2009 +0000
+++ b/src/share/classes/java/util/concurrent/locks/AbstractQueuedSynchronizer.java	Tue Feb 24 14:01:45 2009 -0800
@@ -1445,8 +1445,10 @@
         // 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());
     }