Multithreading and booleans
Posted
by Ikaso
on Stack Overflow
See other posts from Stack Overflow
or by Ikaso
Published on 2010-04-12T08:42:28Z
Indexed on
2010/04/12
8:43 UTC
Read the original article
Hit count: 343
multithreading
|.NET
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,
© Stack Overflow or respective owner