Skip to content
Sharp

Concurrency basics · interview question

Why is the 'volatile' keyword not sufficient for incrementing a shared counter?

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

Correct answer

B. Volatile does not ensure atomicity of operations

Why

Using 'volatile' ensures visibility, but incrementing involves multiple steps (read, modify, write) that are not atomic. Hence, race conditions can still occur.

Test yourself on Concurrency basics

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

Start free test
All Concurrency basics questions →