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 8e26979
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 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() {
synchronized (interruptLock) {
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;
}
return oldValue;
}

/**
Expand Down

0 comments on commit 8e26979

Please sign in to comment.