64位cpu上的64位值的读/写操作是原子的吗? [英] Are reads/writes of 64-bit values atomic on a 64-bit cpu?

查看:495
本文介绍了64位cpu上的64位值的读/写操作是原子的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在32位计算机上,.net中对64位值的读取和写入曾经是非原子的,也就是说,在读取时,我可以读取一个从未写入内存的值,该值由一个较旧的32-

On 32-bit machines, reading and writing of 64-bit values in .net used to be non-atomic, i.e. when reading, I could read a value that had never been written to memory, consisting of one older 32-bit half, and one newer half.


  1. 但是在64位cpus上读写是原子的吗?

  2. 如果是,那么(Windows)操作系统也必须是64位吗?

  3. 如果是这样,甚至该应用程序也必须是64位.net构建吗? ?


推荐答案

来自答案,如果您使用的是64位系统并使用64位CLR,则它们是原子的。答案引用了来自Eric Lippert的此博客文章: https://blogs.msdn.microsoft.com/ericlippert/2011/05/31/atomicity-volatility-and-immutability-are-different-part-two/

From this answer, if you're on a 64 bit system and using a 64-bit CLR, then they are atomic. The answer references this blog post from Eric Lippert: https://blogs.msdn.microsoft.com/ericlippert/2011/05/31/atomicity-volatility-and-immutability-are-different-part-two/


CLI规范实际上提供了更强的保证。 CLI保证读写值类型变量的大小是原子的(或小于处理器的自然指针大小)是原子的;如果在64位版本的CLR上的64位操作系统上运行C#代码,则对64位双精度数的读取和写入和长整数也将保证是原子的。 C#语言不能保证,但是运行时规范可以。 (如果您在某些CLI实现未实现的环境中运行C#代码,那么您当然不能依靠该保证;如果您想知道它们提供的保证,请与向您出售运行时的供应商联系。) / p>

The CLI specification actually makes stronger guarantees. The CLI guarantees that reads and writes of variables of value types that are the size (or smaller) of the processor's natural pointer size are atomic; if you are running C# code on a 64 bit operating system in a 64 bit version of the CLR then reads and writes of 64 bit doubles and long integers are also guaranteed to be atomic. The C# language does not guarantee that, but the runtime spec does. (If you are running C# code in some environment that is not implemented by some implementation of the CLI then of course you cannot rely upon that guarantee; contact the vendor who sold you the runtime if you want to know what guarantees they provide.)

这篇关于64位cpu上的64位值的读/写操作是原子的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆