本文介绍了是否所有*线程缓存数据都在MemoryBarrier处刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 显然,围绕访问某些 共享状态变量的关键部分会刷新所有缓存的数据等,以便所涉及的线程 没有看到陈旧的副本。我想知道的是*什么* 确实被冲洗了。编译器是否有一些如何确定可以从该线程访问的数据,并且只刷新该集合? (似乎 对我来说不太可能)。是否所有数据都缓存在寄存器等中?或者我是否b / b 过度思考而不是更多的事情就是内存 障碍只会使内存页面无效,以至于当另一个 $时b $ b线程去访问它首先检查的内存,看看是否需要从主内存中重新获取页面 ? 感谢您的任何见解, 汤姆Obviously wrapping a critical section around access to some set ofshared state variables flushes any cached data, etc so that the threadsinvolved don''t see a stale copy. What I was wondering is *what*exactly gets flushed. Does the compiler some how determine the datathat is accessible from that thread, and flush just that set? (Seemsunlikely to me). Is it all data cached in registers etc? Or am Ioverthinking this and instead it''s more along the lines that a memorybarrier is just invalidating pages of memory such that when anotherthread goes to access that memory it checks first to see if that pageneeds to be refetched from main memory?Thanks for any insights,Tom推荐答案 它由硬件架构定义。在x86的情况下,刷新的内存量为为0,因为x86处理器具有强大的缓存一致性 保证。在其他架构中,它会有所不同,但在所有情况下, 跟随内存屏障,在屏障之前发出的所有写入将是所有CPU可见的。这是由高速缓存失效,更新其他高速缓存等来完成的,由硬件架构定义,并且通常程序员看不到。 -cdIt''s defined by the hardware architecture. In the case of x86, the amountof memory flushed is 0, becuase x86 processors have strong cache coherencyguarantees. In other architectures it will be different, but in all cases,following a memory barrier, all writes issued before the barrier will bevisible to all CPUs. Whether that''s done by cache invalidation, updatingother caches, etc., is defined by the hardware architecture and generallynot visible to the programmer.-cd 这篇关于是否所有*线程缓存数据都在MemoryBarrier处刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!