Skip to content
Sharp

Concurrency basics · interview question

What does declaring a field volatile guarantee?

Multiple choiceMedium
Choose one answer
Answer and explanation

Correct answer

A. Writes are visible to other threads, with ordering guarantees, but compound actions like count++ are still not atomic.

Why

volatile establishes a happens-before edge between a write and later reads. It's great for flags like running, but not for counters.

Test yourself on Concurrency basics

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

Start free test
All Concurrency basics questions →