Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>No type is truly safe! More precisely, the C# specifications assure you that reading or assignation of structure types less than 4 bytes or references are atomic. if your operating system is 64 bits, the CLR does a little better by assuring the same thing for structures less than 8 bytes.</p> <p>But anything more complicated than an assignation or a read of a value can potentially be interrupted by another competing thread if you are not careful.</p> <p>Even something as simple as this:</p> <pre><code>myBool = !myBool </code></pre> <p>can get an unexpected result if a competing thread modify the value of myBool.</p> <p>Use of locks is advised if you want to be sure something like that does not happen. Use of the volatile keyword is strongly discouraged unless you know exactly what your doing. Check <a href="http://blogs.msdn.com/b/ericlippert/archive/2011/05/26/atomicity-volatility-and-immutability-are-different-part-one.aspx" rel="nofollow">these</a> <a href="http://blogs.msdn.com/b/ericlippert/archive/2011/05/31/atomicity-volatility-and-immutability-are-different-part-two.aspx" rel="nofollow">blog</a> <a href="http://blogs.msdn.com/b/ericlippert/archive/2011/06/16/atomicity-volatility-and-immutability-are-different-part-three.aspx" rel="nofollow">posts</a> for additionnal information.</p> <p>However in your example where the property does not do anything else than a single write or a single read, locking is useless. But it would not be if there was any additionnal treatment.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload