← Quiz: Java Concurrency Utilities: all 10 questions
Quiz: Java Concurrency Utilities · Question 3 of 10
What does compare-and-set (CAS) do?
What does compare-and-set (CAS) do?
- A.Sets a new value only if the current value still equals the expected value
- B.Locks the variable until the thread ends
- C.Compares two objects with equals
- D.Sorts values before setting them
Answer & explanation
Correct answer: Sets a new value only if the current value still equals the expected value
If another thread changed the value in between, CAS fails and the caller retries with the fresh value.
Can you get the rest right without peeking?
Take the timed Quiz: Java Concurrency Utilities quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →