当前位置:网站首页>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.
边栏推荐
- Alibaba senior experts create a learning architecture from scratch, including Alibaba's internal technology stack PPT, PFD actual combat
- 爬虫之selenium
- 【QT】入门心法
- 6000 字+,帮你搞懂互联网架构演变历程!
- 阿里巴巴政委体系-第八章、阿里政委工作方法论
- 盲僧发现了华点——教你如何使用API接口获取数据
- OneNote 教程,如何在 OneNote 中设置页面格式?
- 2022/08/02------Ugly number
- Cobalt Strike (CS) 逆向初探
- Redis:哨兵
猜你喜欢
随机推荐
Zhong Hua, senior architect of Ali: China-Taiwan strategic thinking and architecture practice; including internal implementation manual
C#爬虫之通过Selenium获取浏览器请求响应结果
【微信小程序】NFC 标签打开小程序
MD5是对称加密还是非对称加密,有什么优缺点
阿里巴巴政委体系-第七章、阿里政委培育
Shell:循环语句
idea——同一项目开启多个实例(不同端口)
多线程和并发编程(四)
要想成为黑客,离不开这十大基础知识
力扣刷题之数组序号计算(每日一题7/28)
力扣解法汇总899-有序队列
关于2022年度深圳市技术攻关重大项目的申报通知
懵逼!阿里一面被虐了,幸获内推华为技术四面,成功拿到offer,年薪40w
一文搞懂│php 中的 DI 依赖注入
【QT】入门心法
awk语法-02-运算、数组、格式化输出
go语言实现导出string字符串到文件中
CC2530_ZigBee+华为云IOT:设计一套属于自己的冷链采集系统
SQL代码需要供其他人复用,为什么传统的复制代码不可靠?
BinomialTree 二叉树