Skip to content

Commit

Permalink
Add synchronization when setting interrupted field in Thread::interrupt
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ThanHenderson committed Jul 11, 2024
1 parent 8b9d0dd commit 8d0fff0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/java.base/share/classes/java/lang/Thread.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 8d0fff0

Please sign in to comment.