本文介绍了参考原子分配其尺寸结构体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
快速的问题......假设我有一个C#结构,其中包含一个引用成员。此结构的任务原子在.NET?例如:
结构ReadOnlyList< T>
{
私人列表< T>清单;
//其他随机功能
};
我知道,普通的旧基准任务是原子,只是好奇,如果包裹整个事情在一个结构有什么差别......
感谢
解决方案
所以,唯一的引用类型成员的结构转让的原子是实现定义的,你不应该依赖于它。
Quick question... Suppose I have a C# struct that contains a single reference member. Are assignments of this struct atomic in .NET? For Example:
struct ReadOnlyList<T>
{
private List<T> list;
// other random functionality
};
I know that plain old reference assignments are atomic, just curious if wrapping the whole thing up in a struct makes any difference...
Thanks
解决方案
So atomicity of assignment of a structure with the only reference-type member is implementation defined, and you should not rely on it.
这篇关于参考原子分配其尺寸结构体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!