Multithreading and booleans
- by Ikaso
Hi Everyone,
I have a class that contains a boolean field like this one:
public class MyClass
{
private boolean boolVal;
public boolean BoolVal
{
get { return boolVal; }
set { boolVal = value; }
}
}
The field can be read and written from many threads using the property. My question is if I should fence the getter and setter with a lock statement? Or should I simply use the volatile keyword and save the locking? Or should I totally ignore multithreading since getting and setting boolean values atomic?
regards,