| preferred AP College board partner for AP classes
AP Computer Science A/Unit 5: Writing Classes
Start Practice TestPractice Test
About Exam
hard Solved by 1 students
Java Thread Synchronization Issues
< Prev
Next >

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.

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