.net - Is a bool read/write atomic in C# -
is accessing bool field atomic in c#? in particular, need put lock around:
class foo { private bool _bar; //... in function on thread (or many threads) _bar = true; //... same read if (_bar) { ... } }
yes.
reads , writes of following data types atomic: bool, char, byte, sbyte, short, ushort, uint, int, float, , reference types.
as found in c# language spec.
edit: it's worthwhile understanding volatile keyword.
Comments
Post a Comment