Skip to content
Sharp

Concurrency basics · interview question

How does the 'volatile' keyword affect the visibility of a variable across different CPU caches?

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

Correct answer

C. It ensures the variable is always read from main memory

Why

Volatile ensures that a variable is always read from and written to main memory, bypassing CPU caches. This guarantees visibility of variable changes across threads operating on different cores.

Test yourself on Concurrency basics

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

Start free test
All Concurrency basics questions →