From 10cd86bf39484102a7ed9aebef37fd55f0addba1 Mon Sep 17 00:00:00 2001 From: "randy.jeong" Date: Thu, 8 Oct 2015 19:32:12 +0900 Subject: [PATCH] Fix race in ART 079-phantom Test failure root cause: there is data race between shutDown() and run() of bitmap class: 1st thread sets mQuit field to true and yields to 2nd thread w/o sending interrupt signal to 2nd thread; 2nd thread checks mQuit field and exits w/o printing "intr" message. In other execution scenario, 1st thread yield to 2nd thread only after sending interrupt signal thus causing 2nd thread to execute catch InterruptedException block and print "intr" message (expected test case behavior). Proposed solution: add proper synchronization between Bitmap.shutDown() and run() by removing mQuit field and exiting shutDown when "intr" message is printed. Change-Id: I91946b7fb8bfb6ff2039c40384f8647ba4da98a4 Signed-off-by: randy.jeong --- test/079-phantom/src/Bitmap.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/079-phantom/src/Bitmap.java b/test/079-phantom/src/Bitmap.java index 85eb3ccb9..ff43749e7 100644 --- a/test/079-phantom/src/Bitmap.java +++ b/test/079-phantom/src/Bitmap.java @@ -125,7 +125,6 @@ class PhantomWrapper extends PhantomReference { */ class BitmapWatcher extends Thread { ReferenceQueue mQueue; - volatile boolean mQuit = false; BitmapWatcher(ReferenceQueue queue) { mQueue = queue; @@ -133,7 +132,7 @@ class BitmapWatcher extends Thread { } public void run() { - while (!mQuit) { + while (true) { try { PhantomWrapper ref = (PhantomWrapper) mQueue.remove(); //System.out.println("dequeued ref " + ref.mNativeData + @@ -142,12 +141,12 @@ class BitmapWatcher extends Thread { //ref.clear(); } catch (InterruptedException ie) { System.out.println("intr"); + break; } } } public void shutDown() { - mQuit = true; interrupt(); } } -- 2.11.0