当前位置:网站首页>pg_memory_barrier_impl in Postgresql and C's volatile
pg_memory_barrier_impl in Postgresql and C's volatile
2022-08-03 19:03:00 【mingjie】
pg_memory_barrier_impl in PG
The definition of memory barrier in arch-x86.h:
#define pg_memory_barrier_impl() \__asm__ __volatile__ ("lock; addl $0,0(%%rsp)" : : : "memory", "cc")#endif
lock;addl mean?
- All write operations after the lock will cause bus synchronization, that is, the cpu store buffer will be flushed out, and the cachelines corresponding to other CPUs will be invalidated through the modified address.
- Then this addl adds 0 to the rsp register (the rsp stack pointer points to volatile data, and you need to use rsp to find the variable in memory) Although it will not change the value of rsp, it will trigger the flush action of the store buffer, and thenSync cacheline data across all cores.
- The final effect is that the cacheline is all synchronized once, and the old value will not be read.
C's volatile
When the value modified by volatile is modified, the variable will not be loaded into the register by the compiler; if it is not modified, the CPU may read from the register or from the memory, and the results of concurrent reading on both sides may beinconsistent.
(java's volatile may have its own asm(lock;addr) function, there are differences here)
Difference
volatile prevents the compiler from stuffing the variable into the register. If it goes into the register, the value of the register will be taken directly when reading, and the stroe buffer and cache will not be taken at all, and the memory_barrier synchronization of the cacheline data will have no effect.
边栏推荐
猜你喜欢
随机推荐
Intelligent security contract - delegatecall (2)
MD5是对称加密还是非对称加密,有什么优缺点
安装radondb mysql遇到问题
WEB 渗透之SSRF
字节跳动三面拿offer:网络+IO+redis+JVM+GC+红黑树+数据结构,助你快速进大厂!!
读取 resources 目录下的文件路径的九种方式,你知道多少?
丙二醇二乙酸酯(Propylene Glycol Diacetate)
金鱼哥RHCA回忆录:CL210管理计算资源--管理计算节点+章节实验
【ORACLE】什么时候ROWNUM等于0和ROWNUM小于0,两个条件不等价?
MD5是对称加密还是非对称加密,有什么优缺点
PreFixSum前缀和
Postgresql源码(64)查询执行——子模块Executor(2)执行前的数据结构和执行过程
关于2022年度深圳市技术攻关重大项目的申报通知
excel写入不完全sheet.append方法(openpyxl)
阿里资深专家打造从零开始学架构,含阿里内部技术栈PPT、PFD实战
MySQL超详细安装教程 手把手教你安装MySQL到使用MySQL 最简单的MySQL安装方式,这种方式装,卸载也简单
机器学习的方法总结
不要小看 WebSocket!长连接、有状态、双向、全双工都是王炸技能
U-Net生物医学图像分割讲解(Convolutional Networks for BiomedicalImage Segmentation)
X86函数调用模型分析