有没有一种系统的方法可以知道 C# 中的操作是否是原子操作?或者是否有任何一般准则或经验法则?
最佳答案
对于更完整/详细的内容:
读取和写入 32 位值类型是原子的:这包括以下内在值(结构)类型:bool、char、byte、sbyte、short、ushort、int、uint、float
.以下类型(以及其他类型)不保证是原子的:decimal、double、long、ulong
。
例如
int x;
x = 10; // atomic
decimal d;
d = 10m; // not atomic
引用赋值也是一个原子操作:
private String _text;
public void Method(String text)
{
_text = text; // atomic
}
关于c# - C# 中哪些操作是原子操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55859535/