易变的领域 [英] Volatile fields

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

问题描述

大家好,


让我们专注于32位sigle处理器机器。

1.单处理器机器上的多线程32位我是否

必须同步访问类型小于32位的原子获取/设置属性吗?

2.对于那些属性,它足以在单个处理器上使用volatile

机器?

3确实可以解决多处理器机器的问题吗?

4.问题优化/重新排序/缓存

在32位单处理器机器上出现多线程问题?

谢谢大家。

Hi all,

let be focus on sigle processor machine 32 bits.
1. with multi-threaded on single processor machine 32bit do i
have to sync access to atomic get/set properties of type less then 32 bits ?
2. for those properties is it enough to use volatile on single processor
machine ?
3 does volatile solve the problem for multi-processor machine ?
4. does the problems optimizations/reordering/caching
makes problems with multi-threading on single processor machine 32bit ?

Thanks all.

推荐答案

"亚龙" <亚*** @ discussions.microsoft.com>在留言中写道

新闻:AB ********************************** @ microsof t.com ...
"yaron" <ya***@discussions.microsoft.com> wrote in message
news:AB**********************************@microsof t.com...
大家好,

让我们专注于32位sigle处理器机器。
1.单处理器机器上的多线程32bit我是否必须同步访问类型少于32位的原子get / set属性



您应该同步访问任何类型的数据。

2.对于那些属性是否足以在单处理器
机器上使用volatile?


来自msdn的编号:" volatile关键字是一个类型限定符,用于声明

一个对象可以在程序中通过诸如

操作系统,硬件或同时执行的线程。

Volatile关键字不会使你的变量同步。

3 volatile解决了多处理器机器的问题?


No.

4.问题优化/重新排序/缓存
会在32位单处理器机器上出现多线程问题吗?
Hi all,

let be focus on sigle processor machine 32 bits.
1. with multi-threaded on single processor machine 32bit do i
have to sync access to atomic get/set properties of type less then 32 bits
?
you should sync access to data of any type.
2. for those properties is it enough to use volatile on single processor
machine ?
No. from msdn: "The volatile keyword is a type qualifier used to declare
that an object can be modified in the program by something such as the
operating system, the hardware, or a concurrently executing thread."
Volatile keyword does not make your variable syncronized.
3 does volatile solve the problem for multi-processor machine ?
No.
4. does the problems optimizations/reordering/caching
makes problems with multi-threading on single processor machine 32bit ?




优化中不使用易失性对象,因为它们可以随时修改




-

Vladimir



Volatile object are not used in optimization, because they can be modified
at any time.

--
Vladimir


Scherbina Vladimir写道:
Scherbina Vladimir wrote:
" yaron" <亚*** @ discussions.microsoft.com>在消息中写道
新闻:AB ********************************** @ microsof t.com。 ..
"yaron" <ya***@discussions.microsoft.com> wrote in message
news:AB**********************************@microsof t.com...
大家好,

让我们专注于32位sigle处理器机器。
1.在单处理器机器上使用多线程32bit我可以/>必须同步访问类型少于32位的原子get / set属性
Hi all,

let be focus on sigle processor machine 32 bits.
1. with multi-threaded on single processor machine 32bit do i
have to sync access to atomic get/set properties of type less then 32 bits
?



你应该同步访问任何类型的数据。



you should sync access to data of any type.




是的,虽然volatile用于此目的。



Yes, although volatile serves that purpose.

2.对于那些属性,它足以使用volatile在单处理器
机器上?
2. for those properties is it enough to use volatile on single processor
machine ?



来自msdn的编号:volatile关键字是一个类型限定符,用于声明一个对象可以在通过诸如操作系统,硬件或同时执行的线程之类的程序来编程。
Volatile关键字不会使您的变量同步。



No. from msdn: "The volatile keyword is a type qualifier used to declare
that an object can be modified in the program by something such as the
operating system, the hardware, or a concurrently executing thread."
Volatile keyword does not make your variable syncronized.




除非我弄错了,你引用的是C / C ++文档,其中
并不适用于C#。



Unless I''m mistaken, you''re quoting from the C/C++ documentation, which
doesn''t apply to C#.

3是否可以解决多处理器机器的问题?
3 does volatile solve the problem for multi-processor machine ?



没有。



No.




确实如此实际上 - 对于volatile适合的类型。 (参见下面的
链接。)



It does, actually - for types for which volatile is appropriate. (See
link below.)

4.问题优化/重新排序/缓存是否会产生问题单处理器机器上的多线程32位?
4. does the problems optimizations/reordering/caching
makes problems with multi-threading on single processor machine 32bit ?



易失性对象不用于优化,因为它们可以随时修改。



Volatile object are not used in optimization, because they can be modified
at any time.



这意味着更多。请参阅
http://www.pobox。 com / ~siget / csharp / t ... latility.shtml


Jon



It means a lot more than that. See
http://www.pobox.com/~skeet/csharp/t...latility.shtml

Jon


嗨Jon,


你之前回答我关于这个主题的问题,但我不明白

我的简单例子的结论是什么。

在单处理器32位上可以做什么,而在
多处理器机器上无法做什么? (我的意思是我必须在这32位上使用同步

属性还是不稳定的?)


非常感谢。

" Jon Skeet [C#MVP]"写道:
Hi Jon,

You answer on my questions on this topic before, but i didn''t understand
what are the conclusions on my simple example.
what can be done on single processor 32 bit and what can''t be done on
multi-processor machine ? (i means do i must use sync on those 32 bits
properties or volatile are enough ?)

Thanks a lot.

"Jon Skeet [C# MVP]" wrote:
Scherbina Vladimir写道:
Scherbina Vladimir wrote:
" yaron" <亚*** @ discussions.microsoft.com>在消息中写道
新闻:AB ********************************** @ microsof t.com。 ..
"yaron" <ya***@discussions.microsoft.com> wrote in message
news:AB**********************************@microsof t.com...
大家好,

让我们专注于32位sigle处理器机器。
1.在单处理器机器上使用多线程32bit我可以/>必须同步访问类型少于32位的原子get / set属性
Hi all,

let be focus on sigle processor machine 32 bits.
1. with multi-threaded on single processor machine 32bit do i
have to sync access to atomic get/set properties of type less then 32 bits
?



你应该同步访问任何类型的数据。



you should sync access to data of any type.



是的,虽然volatile可以达到这个目的。



Yes, although volatile serves that purpose.

2.对于那些属性来说,在单个处理器上使用volatile就足够了机器?
2. for those properties is it enough to use volatile on single processor
machine ?



来自msdn的编号:" volatile关键字是一个类型限定符,用于声明一个对象可以在程序中通过类似的东西修改作为
操作系统,硬件或同时执行的线程。
Volatile关键字不会使您的变量同步。



No. from msdn: "The volatile keyword is a type qualifier used to declare
that an object can be modified in the program by something such as the
operating system, the hardware, or a concurrently executing thread."
Volatile keyword does not make your variable syncronized.



除非我'你错了,你引用了C / C ++文档,它不适用于C#。



Unless I''m mistaken, you''re quoting from the C/C++ documentation, which
doesn''t apply to C#.

3 volatile解决了多处理器机器的问题?
3 does volatile solve the problem for multi-processor machine ?



没有。



No.


实际上,对于volatile适合的类型。 (参见下面的
链接。)



It does, actually - for types for which volatile is appropriate. (See
link below.)

4.问题优化/重新排序/缓存是否会导致多线程问题在单处理器机器上32位?
4. does the problems optimizations/reordering/caching
makes problems with multi-threading on single processor machine 32bit ?



易失性对象不用于优化,因为它们可以随时修改。



Volatile object are not used in optimization, because they can be modified
at any time.


这意味着更多。请参阅
http://www.pobox。 com / ~siget / csharp / t ... latility.shtml

Jon



It means a lot more than that. See
http://www.pobox.com/~skeet/csharp/t...latility.shtml

Jon



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

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