I am trying to learn Volatile keyword in Multi Threading and I came across this statement:

Volatile is preferred in cases when one thread reads and writes a shared variable and other threads just read the same. Whereas if there are more than 2 threads performing read and write both on the shared variable then only volatile is not enough, you need to have synchronisation as well.

I am aware of the volatility concept and synchronisation, so can someone please provide an example relating to the above statement?

One thread can both read and write a volatile variable, all the other threads can only read it. You say you are aware of the concept, so what exactly is confusing you, and what exactly do you want an example to show?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.