I am very confused about this subject - whether reading/toggling a bool value is thread-safe.
// case one, nothing
private bool v1;
public bool V1 { get { return v1; } set { v1 = value; } }
// case two, with Interlocked on set
private int v2;
public int V2 { get { return v2; } set { Interlocked.Exchange(ref v2, value); } }
// case three, with lock on set
private object fieldLock = new object();
private bool v3;
public bool V3 { get { return v3; } set { lock (fieldLock) v3 = value; } }
Are all of them thread-safe?
EDIT
From what I have read (click) atomicity of bool does not guarantee it will be thread safe. Will then volatile
type help?