- 浏览: 401035 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (309)
- xaml C# wpf (0)
- scala java inner clas (1)
- Tools UML Eclipse UML2 (1)
- Timer .NET Framework (1)
- perl (6)
- python function paramter (1)
- Python Docstring (1)
- Python how to compare types (1)
- Python (8)
- java (5)
- C# (76)
- C# WPF (0)
- p4 (0)
- WPF (46)
- .net (6)
- xaml (1)
- javascript (40)
- windows (10)
- scala (4)
- winform (1)
- c++ (48)
- tools (12)
- cmd (1)
- os (0)
- CI (0)
- shell (0)
- C (2)
- haskell (49)
- functional (1)
- tool (1)
- gnu (1)
- linux (1)
- kaskell (0)
- svn (0)
- wcf (3)
- android (1)
最新评论
Memory barrier is a synchornization mechanism where all operation (read and/or write) must hold until certain conditions occurs (e.g. when some variable finish writing, or finishi reading, or more than one thread reach one point)...
C# may or may not have the memory barriers interfaces (this require more research work), however, in this topic, we are goiong to focus on the semantics of memory barrier and how the lock and volatile related to the memory barriers.
as may be pointted out by this post - Memory Barriers by lock statement.
Brian Giedon - http://stackoverflow.com/users/158779/brian-gideon 写道
The subject of memory barriers is quite complex. It even trips up the experts from time to time. When we talk about a memory barrier we are really combining two different ideas.
* Acquire fence: A memory barrier in which other reads & writes are not allowed to move before the fence.
* Release fence: A memory barrier in which other reads & writes are not allowed to move after the fence.
A memory barrier that creates only one of two is sometimes called a half-fence. A memory barrier that creates both is sometimes called a full-fence.
The volatile keyword creates half-fences. Reads of volatile fields have acquire semantics while writes have release semantics. That means no instruction can be moved before a read or after a write.
The lock keyword creates full-fences on both boundaries (entry and exit). That means no instruction can be moved either before or after each boundary.
However, all of this moot if we are only concerned with one thread. Ordering, as it is perceived by that thread, is always preserved. In fact, without that fundamental guarentee no program would ever work right. The real issue is with how other threads perceive reads and writes. That is where you need to be concerned.
So to answer your questions:
1. From a single thread's perspective...yes. From another thread's perspective...no.
2. It depends. That might work, but I need to have better understanding of what you are trying to acheive.
3. From another thread's perspective...no. The reads and writes are free to move around within the boundaries of the lock. They just cannot move outside those boundaries. That is why it is important for other threads to also create memory barriers.
* Acquire fence: A memory barrier in which other reads & writes are not allowed to move before the fence.
* Release fence: A memory barrier in which other reads & writes are not allowed to move after the fence.
A memory barrier that creates only one of two is sometimes called a half-fence. A memory barrier that creates both is sometimes called a full-fence.
The volatile keyword creates half-fences. Reads of volatile fields have acquire semantics while writes have release semantics. That means no instruction can be moved before a read or after a write.
The lock keyword creates full-fences on both boundaries (entry and exit). That means no instruction can be moved either before or after each boundary.
However, all of this moot if we are only concerned with one thread. Ordering, as it is perceived by that thread, is always preserved. In fact, without that fundamental guarentee no program would ever work right. The real issue is with how other threads perceive reads and writes. That is where you need to be concerned.
So to answer your questions:
1. From a single thread's perspective...yes. From another thread's perspective...no.
2. It depends. That might work, but I need to have better understanding of what you are trying to acheive.
3. From another thread's perspective...no. The reads and writes are free to move around within the boundaries of the lock. They just cannot move outside those boundaries. That is why it is important for other threads to also create memory barriers.
NOTE:
there may be more content following this discusion.
发表评论
-
wpf - example to enhance ComboBox for AutoComplete
2014-09-19 15:56 1979first let’s see an example ... -
Investigate and troubleshoot possible memory leak issue of .NET application
2014-07-31 10:42 0Hi All, I would like to sh ... -
C# – CoerceValueCallback合并、替换元数据值
2013-08-05 21:59 1929Topic: C# – CoerceValueCallbac ... -
wpf – ListView交替背景色
2013-07-02 20:56 6554Wpf – Alternate background col ... -
C# - 简单介绍TaskScheduler
2013-06-29 17:18 12054标题: C# - 简单介绍TaskSchedulerTit ... -
c# - Get enum from enum attribute
2013-06-27 21:32 1252DescriptionAttribute gives the ... -
C# - PInvoke, gotchas on the RegisterClassEx and the CreateWindowEx
2013-06-24 13:49 2576I get an exception message li ... -
c# - Use PInvoke to create simple win32 Application
2013-06-24 11:59 10953In this post, .net platform h ... -
c# - Linq's Select method as the Map function
2013-06-19 18:47 1294If you comes from a functiona ... -
c# - Tips of Linq expression Any to determine if a collection is Empty
2013-06-19 18:29 942When you are @ the linq expres ... -
myth buster - typeof accepting array of types not acceptable
2013-06-19 17:17 819I have seen from some book whe ... -
windows - trying to create WIN32 application with PInvoke
2013-06-19 14:34 0While it is stupid to do such ... -
WPF - Setting foreground color of Entire window
2013-06-13 16:00 1925You might as well as I would s ... -
WPF - Enhanced TabControl - TabControlEx aka Prerendering TabControl
2013-06-13 13:12 5337As an opening word, let's che ... -
wpf - ControlTemplate and AddLogicChild/RemoveLogicalChild
2013-06-10 15:42 1191Recently I was trying to debug ... -
c# - P/Invoke, DllImport, Marshal Structures and Type conversions
2013-06-05 15:25 1717P/Invoke as in the following q ... -
c# - A study on the NativeWindow - encapsulate window handle and procedure
2013-06-05 14:40 6099NativeWindow gives you a way t ... -
WCF - Notify server when client connects
2013-06-03 18:19 1227It is sometimes very importan ... -
wcf - Debug to enable Server exception in Fault message
2013-06-03 15:47 1098WCF will be able to send back ... -
c# - determine if a type/object is serialzable
2013-05-30 16:35 870In WCF, primitives type are s ...
相关推荐
### Linux Memory Barrier原理详解 #### 一、Memory Barrier概述 在多处理器系统(SMP)中,内存访问顺序和同步成为影响程序正确性和性能的关键因素。Linux 内核中的 Memory Barrier(内存屏障)机制用于控制...
– CPU Memory Ordering模型 (Atomic,Reorder,Memory Barrier (Compiler, CPU),Lock Instruction,Load Acquire/Store Release); – 并发程序设计 (实现一个Spinlock,纠正一个Lock-Free Algorithm, Data Race ...
ARM Cortex™-M系列处理器的内存屏障指令编程指南是一份关于ARM公司推出的Cortex™-M微处理器架构中内存屏障(Memory Barrier)指令的指导性技术文档。这份应用笔记涵盖了ARM Cortex™-M处理器的流水线特性,及其在...
Linux内存屏障(Memory Barrier)是一种用于控制指令执行顺序的机制,它在多处理器(SMP)环境下尤为重要。在理解内存屏障之前,我们首先需要了解CPU缓存以及缓存一致性协议是如何工作的,因为这些都是理解内存屏障...
在底层实现上,volatile关键字依赖于JVM的内存模型(Memory Model)和处理器的内存屏障(Memory Barrier)。内存屏障是一种硬件指令,它可以阻止特定类型的指令重排序,并强制将某些操作立即写入内存。在Java中,...
1、通过dispatch_barrier_(a)sync添加的block会等待前边所有的block执行完(不包括回调)才执行。 2、在其后添加的block会在dispatch_barrier_(a)sync添加的block执行完之后(不包括回调)再执行; 不同点: 1、...
当使用这些宏定义时,虽然可以看作是volatile的memory_order_relaxed访问,但是它们通常只适用于适当的对齐的机器字大小变量。除此之外,`smp_store_release()`和`smp_load_acquire()`宏分别提供了释放型和获取型的...
- **内存屏障**(Memory Barrier):防止编译器和处理器对指令进行重排序的一种机制。 - **编译器内存屏障**(Compiler Memory Barrier):防止编译器对指令进行重排序。 - **处理器内存屏障**(Processor Memory ...
如果你有2台电脑,一台ubuntu,一台windows,在不断的切换之间,你会感觉到 手也要在不同的鼠标,不同的键盘之间切换很繁琐,那么使用 barrier,可以帮你解这种烦恼,它用来在 ubuntu 和 windows 之间 定义一个电脑...
**标题解析:** "barrier.zip (synergy免费版)" 提供的是一个名为"barrier"的软件压缩包,该软件是Synergy的免费版本。Synergy是一款强大的跨平台工具,允许用户通过单一的鼠标和键盘控制多台计算机,实现多设备间的...
在众多CO2转化技术中,利用电介质阻挡放电(Dielectric Barrier Discharge,DBD)等离子体与光催化剂的协同作用,提供了一条新的技术路线。DBD等离子体是一种非热等离子体,能够在相对较低的温度下产生高能电子、...
MPI Barrier是Message Passing Interface (MPI)库中的一个关键同步原语,它在并行计算中起着至关重要的作用。MPI_BARRIER函数允许所有参与进程在继续执行下一个阶段之前等待彼此到达一个预定义的同步点,确保所有...
Effects of Gibbs free energy changes and energy barrier on mechanochemical synthesis of LiMn2O4,赵中伟,欧阳全胜,本研究以KMnO4和MnSO4•H2O粉末为Mn源,LiOH•H2O粉末为Li源,在室温条件下粉磨合成LiMn2O4...
barrier windows 安装文件
Measured data that validates the inclusion of important small-geometry effects like velocity saturation, vertical-field mobility reduction, drain-induced barrier lowering, and inversion-level ...
mb garanties that all loads and stores before the barrier will be visible to all processors before any loads and stores after the barrier. 在编程中,内存屏障通常用于多线程编程中,用于保证多个线程...
C/C++ 中的 volatile 关键字和 const 对应,用来修饰变量,通常用于建立语言级别的 memory barrier。这是 BS 在 “The C++ Programming Language” 对 volatile 修饰词的说明: A volatile specifier is a hin
然而,volatile并不能阻止CPU对其他非volatile变量的重排序和缓存策略,因此在某些场景下,还需要使用内存栅栏(Memory Barrier)来确保数据同步。内存栅栏是一种指令,它强制在栅栏之前和之后的指令不发生交叉执行...