Java Thread Synchronization Issues
In a multi-threaded context, what major problem can occur with the implementation of FlagCheck?
public class FlagCheck {
private boolean flag = false;
public void setTrue() { flag = true; }
public void waitForFlag() {
while(!flag) {
// busy-wait
}
System.out.println("Flag is true");
}
}
A
An infinite loop due to improper use of the volatile keyword.
B
Deadlock since the busy-wait loop prevents lock release.
C
Race condition and memory visibility issues because ‘flag’ is neither volatile nor accessed within a synchronized block.
D
The program will always compile with no runtime issues.
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE