I have good knowledge of synchronization
internals and basic knowledge of volatile
internals.
I have one query, which is follow-up to below SE question:
Why is volatile used in this example of double checked locking
I'm confused about one part. If I strictly follow above example, I have to add volatile
to many variables but I am sure that all multi-threaded applications are not using this volatile + synchronized combination.
If synchronization
is not guaranteeing memory consistency as per above example, what are the use cases of using combination of volatile
variables with synchronization
code?