| preferred AP College board partner for AP classes
AP Computer Science A/Unit 5: Writing Classes
Start Practice TestPractice Test
About Exam
hard
Java Volatile Keyword and Atomicity
< Prev
Next >

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.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy