Skip to content
Sharp

Concurrency basics · interview question

Why might using 'volatile' alone be insufficient for ensuring thread safety when updating a shared counter?

Multiple choiceMediumchapter-15-curatedpremiumconcurrencythe-volatile-keyword
Choose one answer
Answer and explanation

Correct answer

B. Volatile does not guarantee atomic updates

Why

Using 'volatile' alone does not ensure atomicity. Increment operations involve reading, modifying, and writing back the value, which can lead to race conditions if done without synchronization.

Test yourself on Concurrency basics

A free test with instant, explained results. No account needed.

Start free test
All Concurrency basics questions →