Skip to content

Commit

Permalink
Add synchronized block in getAndClearInterrupt()
Browse files Browse the repository at this point in the history
Fixes: eclipse-openj9/openj9#15465
Port of ibmruntimes/openj9-openjdk-jdk19#51

Signed-off-by: Hang Shao <hangshao@ca.ibm.com>
  • Loading branch information
hangshao0 committed Nov 29, 2022
1 parent f12886d commit 5695cda
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/java.base/share/classes/java/lang/Thread.java
Original file line number Diff line number Diff line change
Expand Up @@ -1756,15 +1756,14 @@ final void clearInterrupt() {
}

boolean getAndClearInterrupt() {
boolean oldValue = interrupted;
// We may have been interrupted the moment after we read the field,
// so only clear the field if we saw that it was set and will return
// true; otherwise we could lose an interrupt.
if (oldValue) {
interrupted = false;
clearInterruptEvent();
}
return oldValue;
synchronized (interruptLock) {
boolean oldValue = interrupted;
if (oldValue) {
interrupted = false;
clearInterruptEvent();
}
return oldValue;
}
}

/**
Expand Down

0 comments on commit 5695cda

Please sign in to comment.