Volatile Fields
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)
Primitive Types
Enumeration Types
public class Animal
{
private volatile int _Age;
}
Any fields that are declared as volatile are not subject to compiler optimisations.
Multi-Threading
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.
More Details
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext