Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Add synchronized block in getAndClearInterrupt() #51

Merged
merged 1 commit into from
Dec 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1813,15 +1813,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