Java Volatile Keyword and Atomicity
Even though the ‘done’ variable is declared as volatile, what concurrency issue still exists in the checkAndReset() method?
public class VolatileFlag {
private volatile boolean done = false;
public void checkAndReset() {
if (done) {
done = false;
}
}
}
A
Race condition due to the non-atomic check-and-act operation.
B
Memory visibility problems remain unresolved.
C
Compilation failure due to improper volatile usage.
D
Deadlock because volatile variables can induce locking issues.
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE