原子操作 [英] Atomic operations

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

问题描述



更新时可以安全删除数据结构上的锁定

仅限于更换引用?换句话说,设置一个引用

原子操作?


我一直假设< = 1个数据字的所有写入都是原子的。这是

实际记录在哪里吗?


-

Jon D Harrop博士,飞蛙咨询公司
http://www.ffconsultancy.com/products/?u

推荐答案

Jon Harrop写道:
Jon Harrop wrote:

更新时可以安全删除数据结构上的锁

仅限于更换参考?换句话说,设置一个引用

原子操作?


我一直假设< = 1个数据字的所有写入都是原子的。这个

实际记录在哪里吗?
Can read locks on a data structure be removed safely when updates are
limited to replacing a reference? In other words, is setting a reference an
atomic operation?

I have been assuming that all writes of <=1 word of data are atomic. Is this
actually documented anywhere?



ECAM-334说:


12.5变量引用的原子性

读写以下数据类型应为原子:bool,

char,byte,sbyte,short,ushort,

uint,int,float和reference types。此外,上一个列表中具有底层类型



枚举类型的读写也应该是原子的。其他

类型的读写,包括long,ulong,double,

来自库函数设计

为此目的,没有保证原子读 - 修改 - 写,

如在增量或

减少的情况。


我读了和参考类型好像读写一个

参考是原子的。


Arne

ECAM-334 says:

12.5 Atomicity of variable references
Reads and writes of the following data types shall be atomic: bool,
char, byte, sbyte, short, ushort,
uint, int, float, and reference types. In addition, reads and writes of
enum types with an underlying type
in the previous list shall also be atomic. Reads and writes of other
types, including long, ulong, double,
and decimal, as well as user-defined types, need not be atomic. Aside
from the library functions designed
for that purpose, there is no guarantee of atomic read-modify-write,
such as in the case of increment or
decrement.

and I read the "and reference types" as if reading and writing a
reference is atomic.

Arne


Jon Skeet [C#MVP]写道:
Jon Skeet [C# MVP] wrote:

4月19日,6:34 * am,Jon Harrop< j ... @ ffconsultancy.comwrote:
On Apr 19, 6:34*am, Jon Harrop <j...@ffconsultancy.comwrote:

>当更新仅限于替换参考时,可以安全地删除数据结构上的锁读取吗?
>Can read locks on a data structure be removed safely when updates are
limited to replacing a reference?



No.


No.


>换句话说,是设置一个原子操作的引用?
>In other words, is setting a reference an atomic operation?



是的,但那不是一回事。


原子性保证你不会看到无效的价值 - 但它

并不意味着你会看到*最新的*值。


Yes, but that''s not the same thing.

Atomicity guarantees that you won''t see an invalid value - but it
doesn''t mean you''ll see the *latest* value.



我不需要看到最新的价值。


如果线程X正在写,那我就不会''假设线程Y读取旧的或

新值,只要它被正确读取。


我认为用对象A替换对象A的引用是正确的对线程X中对象B的
引用将在线程Y中产生有效的A或B?


-

博士飞行青蛙顾问Jon D Harrop
http://www.ffconsultancy。 com / products /?u


Arne Vajh?j写道:
Arne Vajh?j wrote:

Jon Harrop写道:
Jon Harrop wrote:

>当更新仅限于替换引用时,可以安全地删除数据结构上的锁读取吗?换句话说,是设置一个原子操作的引用?

我一直假设< = 1个数据字的所有写操作都是原子的。
这实际记录在哪里?
>Can read locks on a data structure be removed safely when updates are
limited to replacing a reference? In other words, is setting a reference
an atomic operation?

I have been assuming that all writes of <=1 word of data are atomic. Is
this actually documented anywhere?



ECAM-334说:


12.5变量引用的原子性

读写以下数据类型应为原子:bool,

char,byte,sbyte,short,ushort,

uint,int,float和reference types。此外,上一个列表中具有底层类型



枚举类型的读写也应该是原子的。其他

类型的读写,包括long,ulong,double,

来自库函数设计

为此目的,没有保证原子读 - 修改 - 写,

如在增量或

减少的情况。


我读了和参考类型好像读写一个

引用是原子的。


ECAM-334 says:

12.5 Atomicity of variable references
Reads and writes of the following data types shall be atomic: bool,
char, byte, sbyte, short, ushort,
uint, int, float, and reference types. In addition, reads and writes of
enum types with an underlying type
in the previous list shall also be atomic. Reads and writes of other
types, including long, ulong, double,
and decimal, as well as user-defined types, need not be atomic. Aside
from the library functions designed
for that purpose, there is no guarantee of atomic read-modify-write,
such as in the case of increment or
decrement.

and I read the "and reference types" as if reading and writing a
reference is atomic.



听起来不错。 :-)


-

Jon D Harrop博士,Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u


这篇关于原子操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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