A volatile modifier can be used to indicate that a field can be modified by the operating system, hardware or another concurrently executing thread
The volatile keyword can be applied to fields of the following types
Reference Types (the reference is volatile, not where it actually points to)
public class Animal
private volatile int _Age;
Any fields that are declared as volatile are not subject to compiler optimisations.
You can get unpredictable results when using non-volatile fields in a multi-threaded application.
The compiler will perform optimization techniques on non-volatile fields which can cause unexpected results when using multi-threading.
© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited TopPrevNext