.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

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -