您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

.net – CIL指令是原子的吗?

5b51 2022/1/14 8:22:12 python 字数 2234 阅读 519 来源 www.jb51.cc/python

.Net运行时是否对CIL指令的原子性做出任何保证?如果是这样,他们是什么?所有CIL指令都是原子的吗?或者它是否依赖于JIT编译器生成的机器代码的原子性,因此太平台特定于做出任何保证? C#规范谈到了这一点,同样的事实基本上也适用于CIL;基本上,所有最多4个字节的整数类型都是原子保证的,并且任何引用读/写都是保证原子的. 但是,除此之外没有任何保证;例如,double不保证是原子的 – 这里I

概述

但是,除此之外没有任何保证;例如,double不保证是原子的 – 这里Interlocked可能会有所帮助.

引用ECMA 335(公共语言基础结构(CLI)分区I到VI)

12.6.6 Atomic reads and writes

A conforming CLI shall guarantee that
read and write access to properly
aligned memory locations no larger
than the native word size (the size of
type native int) is atomic (see
§12.6.2) when all the write accesses
to a location are the same size.
Atomic writes shall alter no bits
other than those written. Unless
explicit layout control (see
Partition II (Controlling Instance
Layout)) is used to alter the default
behavior,data elements no larger
than the natural word size (the size
of a native int) shall be properly
aligned. Object references shall be
treated as though they are stored in
the native word size.

[Note: There is
no guarantee about atomic update
(read-modify-write) of memory,except
for methods provided for that purpose
as part of the class library (see
Partition IV). An atomic write of a
―small data item‖ (an item no larger
than the native word size) is required
to do an atomic read/modify/write on
hardware that does not support direct
writes to small data items. end note]

[Note: There is no guaranteed atomic
access to 8-byte data when the size of
a native int is 32 bits even though
some implementations might perform
atomic operations when the data is
aligned on an 8-byte boundary. end
note]

由于native int必须至少为32位,这是它可以提供的最大保证.

总结

以上是编程之家为你收集整理的.net – CIL指令是原子的吗?全部内容,希望文章能够帮你解决.net – CIL指令是原子的吗?所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶