Search code examples
javamultithreadingconcurrencyvolatile

CPU Single Core : Need volatile or synchronized?


In Java, Volatile and synchronized make multithreads can work together and understand each others as well. But, if you use multithread on single-core system, it mean not really multithread work, OS just changes from this thread to thread. (So, one variable just use ONE at exactly moment)

So, I think it not necessary to use safe-thread technique such as volatile or synchronized. Does it true ?

thanks :)


Solution

  • Synchronization is independent of how many cores. It is based on how many threads competing for shared resource. When more than one thread competing you need Synchronization.