.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

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

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

unit testing - How to mock PreferenceManager in Android? -