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 3517096
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 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();
synchronized (interruptLock) {
boolean oldValue = interrupted;
if (oldValue) {
interrupted = false;
clearInterruptEvent();
}
return oldValue;
}
return oldValue;
}

/**
Expand Down

0 comments on commit 3517096

Please sign in to comment.