From d07453889fd9f314849df8c172afadb477e46d64 Mon Sep 17 00:00:00 2001 From: Aart Bik Date: Wed, 23 Mar 2016 11:31:28 -0700 Subject: [PATCH] Fix potential race condition with threads array. Rationale: Array should be filled with threads prior to first fork, since only in that case does Java memory model ensure all threads have consistent view of array, which itself is subject to one test. BUG=27805463 Change-Id: I28f1eb8461842217ced2255062d2135ef880e7d5 --- test/004-checker-UnsafeTest18/src/Main.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/004-checker-UnsafeTest18/src/Main.java b/test/004-checker-UnsafeTest18/src/Main.java index c50613d58..282f9ce0d 100644 --- a/test/004-checker-UnsafeTest18/src/Main.java +++ b/test/004-checker-UnsafeTest18/src/Main.java @@ -133,6 +133,10 @@ public class Main { private static void fork(Runnable r) { for (int i = 0; i < 10; i++) { sThreads[i] = new Thread(r); + } + // Start the threads only after the full array has been written with new threads, + // because one test relies on the contents of this array to be consistent. + for (int i = 0; i < 10; i++) { sThreads[i].start(); } } -- 2.11.0