是否所有*线程缓存数据都在MemoryBarrier处刷新 [英] Is *all* thread cached data flushed at MemoryBarrier

查看:76
本文介绍了是否所有*线程缓存数据都在MemoryBarrier处刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,围绕访问某些

共享状态变量的关键部分会刷新所有缓存的数据等,以便所涉及的线程

没有看到陈旧的副本。我想知道的是*什么*

确实被冲洗了。编译器是否有一些如何确定可以从该线程访问的数据,并且只刷新该集合? (似乎

对我来说不太可能)。是否所有数据都缓存在寄存器等中?或者我是否b / b
过度思考而不是更多的事情就是内存

障碍只会使内存页面无效,以至于当另一个
$时b $ b线程去访问它首先检查的内存,看看是否需要从主内存中重新获取页面




感谢您的任何见解,

汤姆

Obviously wrapping a critical section around access to some set of
shared state variables flushes any cached data, etc so that the threads
involved don''t see a stale copy. What I was wondering is *what*
exactly gets flushed. Does the compiler some how determine the data
that is accessible from that thread, and flush just that set? (Seems
unlikely to me). Is it all data cached in registers etc? Or am I
overthinking this and instead it''s more along the lines that a memory
barrier is just invalidating pages of memory such that when another
thread goes to access that memory it checks first to see if that page
needs to be refetched from main memory?

Thanks for any insights,
Tom

推荐答案




我做的不明白你的问题是什么。 MemoryBarrier(根据

到MSDN)在Itanium处理器中才有意义,不确定.net

是否真的移植到itanium上。


我的建议是尝试查看非托管

世界中的等价物。

-

- -

Ignacio Machin,

ignacio.machin at dot.state.fl.us

佛罗里达州交通局

< NO *********** @ lycos.com写信息

新闻:11 ************** ********@b28g2000cwb.googlegr oups.com ...
Hi,

I do not understand clearly what is your question. MemoryBarrier (according
to MSDN) is only significative in Itanium processors, not sure if the .net
is even ported to the itanium to be honest.

My suggestion is to try to see what is the equivalent in the unmanaged
world.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<NO***********@lycos.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...

显然围绕访问一些关键部分

共享状态变量刷新任何缓存的数据等,以便涉及的线程

看不到陈旧的副本。我想知道的是*什么*

确实被冲洗了。编译器是否有一些如何确定可以从该线程访问的数据,并且只刷新该集合? (似乎

对我来说不太可能)。是否所有数据都缓存在寄存器等中?或者我是否b / b
过度思考而不是更多的事情就是内存

障碍只会使内存页面无效,以至于当另一个
$时b $ b线程去访问它首先检查的内存,看看是否需要从主内存中重新获取页面




感谢您的任何见解,

Tom
Obviously wrapping a critical section around access to some set of
shared state variables flushes any cached data, etc so that the threads
involved don''t see a stale copy. What I was wondering is *what*
exactly gets flushed. Does the compiler some how determine the data
that is accessible from that thread, and flush just that set? (Seems
unlikely to me). Is it all data cached in registers etc? Or am I
overthinking this and instead it''s more along the lines that a memory
barrier is just invalidating pages of memory such that when another
thread goes to access that memory it checks first to see if that page
needs to be refetched from main memory?

Thanks for any insights,
Tom



在隐式读取和
执行写入内存屏障以确保当前线程

不会查看陈旧状态。值(一个在
缓存/寄存器/等中)。这就是(例如)你不能在一个简单的布尔值上执行循环的原因,等待它被另一个线程更改为
。 观看布尔值改变后,线程很可能继续循环

,因为它看到了陈旧的值。

我的问题是,当执行这个内存屏障时,什么是设置

数据被刷新或失效(强制通读)

或通过写入,或其他任何。


Tom


Ignacio Machin(.NET / C#MVP)写道:
When a lock is performed (or Monitor enetr/exit) in implicit read and
write memory barrier is performed to assure that the current thread
does not look at a "stale" value (one that was in a
cache/register/etc). This is the reason (for example) that you cannot
perform a loop on a simple boolean, waiting for it to be changed by
another thread. The "watching" thread is likely to continue to loop
after the boolean has changed value because it is seeing a stale value.
My question is, when this memory barrier is performed, what is the set
of data that gets flushed or gets invalidated (forcing a readthrough)
or gets written-through, or whatever.

Tom

Ignacio Machin ( .NET/ C# MVP ) wrote:




我不明白你的问题是什么。 MemoryBarrier(根据

到MSDN)在Itanium处理器中才有意义,不确定.net

是否真的移植到itanium上。


我的建议是尝试查看非托管

世界中的等价物。


-

-

Ignacio Machin,

ignacio.machin AT dot.state.fl.us

佛罗里达州交通部

< NO *********** @ lycos.com写信息

新闻:11 ********** ************@b28g2000cwb.googlegr oups.com ...
Hi,

I do not understand clearly what is your question. MemoryBarrier (according
to MSDN) is only significative in Itanium processors, not sure if the .net
is even ported to the itanium to be honest.

My suggestion is to try to see what is the equivalent in the unmanaged
world.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<NO***********@lycos.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...

显然围绕访问某些

共享状态变量刷新任何缓存的数据等,以便涉及的线程没有看到过时的副本。我想知道的是*什么*

确实被冲洗了。编译器是否有一些如何确定可以从该线程访问的数据,并且只刷新该集合? (似乎

对我来说不太可能)。是否所有数据都缓存在寄存器等中?或者我是否b / b
过度思考而不是更多的事情就是内存

障碍只会使内存页面无效,以至于当另一个
$时b $ b线程去访问它首先检查的内存,看看是否需要从主内存中重新获取页面




感谢您的任何见解,

Tom
Obviously wrapping a critical section around access to some set of
shared state variables flushes any cached data, etc so that the threads
involved don''t see a stale copy. What I was wondering is *what*
exactly gets flushed. Does the compiler some how determine the data
that is accessible from that thread, and flush just that set? (Seems
unlikely to me). Is it all data cached in registers etc? Or am I
overthinking this and instead it''s more along the lines that a memory
barrier is just invalidating pages of memory such that when another
thread goes to access that memory it checks first to see if that page
needs to be refetched from main memory?

Thanks for any insights,
Tom


NO *********** @ lycos.com 写道:

执行锁定时(或监视enetr / exit)隐式读取和

写入内存屏障是为了确保当前线程

不会看到陈旧状态。值(一个在
缓存/寄存器/等中)。这就是(例如)你不能在一个简单的布尔值上执行循环的原因,等待它被另一个线程更改为
。 观看布尔值改变后,线程很可能会继续循环

,因为它看到了陈旧的

值。


我的问题是,当执行此内存屏障时,刷新或失效的数据设置是什么?(强制通读)

或写入,或者随你。
When a lock is performed (or Monitor enetr/exit) in implicit read and
write memory barrier is performed to assure that the current thread
does not look at a "stale" value (one that was in a
cache/register/etc). This is the reason (for example) that you cannot
perform a loop on a simple boolean, waiting for it to be changed by
another thread. The "watching" thread is likely to continue to loop
after the boolean has changed value because it is seeing a stale
value.
My question is, when this memory barrier is performed, what is the set
of data that gets flushed or gets invalidated (forcing a readthrough)
or gets written-through, or whatever.



它由硬件架构定义。在x86的情况下,刷新的内存量为
为0,因为x86处理器具有强大的缓存一致性

保证。在其他架构中,它会有所不同,但在所有情况下,

跟随内存屏障,在屏障之前发出的所有写入将是所有CPU可见的
。这是由高速缓存失效,更新其他高速缓存等来完成的,由硬件架构定义,并且通常程序员看不到



-cd

It''s defined by the hardware architecture. In the case of x86, the amount
of memory flushed is 0, becuase x86 processors have strong cache coherency
guarantees. In other architectures it will be different, but in all cases,
following a memory barrier, all writes issued before the barrier will be
visible to all CPUs. Whether that''s done by cache invalidation, updating
other caches, etc., is defined by the hardware architecture and generally
not visible to the programmer.

-cd


这篇关于是否所有*线程缓存数据都在MemoryBarrier处刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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