From 8d0fff049b7b2c647fe50344d513e08d007f68d1 Mon Sep 17 00:00:00 2001 From: Nathan Henderson Date: Thu, 11 Jul 2024 10:19:18 -0400 Subject: [PATCH] Add synchronization when setting interrupted field in Thread::interrupt This patch fixes eclipse-openj9/openj9#19304. Setting the interrupted field to true and calling interrupt0 in Thread::interrupt used to be synchronized via interruptLock. An OpenJDK change removed this synchronization which caused a data race on the interrupted field with ReentrantLockTest leading to intermittent test failures. This patch adds the synchronized block around setting interrupted and calling interrupt0 and eliminates the data race with ReentrantLockTest. Issues: eclipse-openj9/openj9#19304 Signed-off-by: Nathan Henderson --- src/java.base/share/classes/java/lang/Thread.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/java.base/share/classes/java/lang/Thread.java b/src/java.base/share/classes/java/lang/Thread.java index 4c7cf3019b6..d77a8cc9758 100644 --- a/src/java.base/share/classes/java/lang/Thread.java +++ b/src/java.base/share/classes/java/lang/Thread.java @@ -1724,8 +1724,10 @@ public void interrupt() { } // Setting the interrupt status must be done before reading nioBlocker. - interrupted = true; - interrupt0(); // inform VM of interrupt + synchronized (interruptLock) { + interrupted = true; + interrupt0(); // inform VM of interrupt + } // thread may be blocked in an I/O operation if (this != Thread.currentThread()) {