Is there a systematic way to know whether an operation in C# will be atomic or not? Or are there any general guidelines or rules of thumb?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
From the CLI specifications you can get here:
Section 12.5 from the C# specification here:
Make the increment operation atomic with this.
For something more complete/detailed:
Reads and writes to 32-bit value types are atomic: This includes the following intrinsic value (struct) types:
bool, char, byte, sbyte, short, ushort, int, uint, float
. The following types (amongst others) are not guaranteed to be atomic:decimal, double, long, ulong
.e.g.
Reference assignment is also an atomic operation:
Yes. Read the CLI specification: http://www.ecma-international.org/publications/standards/Ecma-335.htm. For instance:
I.12.6.6 Atomic reads and writes
Regarding the 64-bit long question, Eric Lippert answers it here: http://blogs.msdn.com/b/ericlippert/archive/2011/05/31/atomicity-volatility-and-immutability-are-different-part-two.aspx