当前位置:网站首页>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")#endiflock;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.
边栏推荐
猜你喜欢

pytest接口自动化测试框架 | Jenkins集成初探

MD5是对称加密还是非对称加密,有什么优缺点

MySQL【变量、流程控制与游标】

【夜莺监控方案】08-监控msyql集群(prometheuse+n9e+mysqld_exporter)

JumpServer开源堡垒机完成龙芯架构兼容性认证

系统太多,多账号互通如何实现?

Higher mathematics - chapter ten infinite series - constant term series

Radondb mysql installation problems

MySQL详细学习教程(建议收藏)

BinomialTree 二叉树
随机推荐
POJ 3041 Asteroids(最大匹配数=最小点覆盖)
ImportError: /lib/libgdal.so.26: undefined symbol: sqlite3_column_table_name
G6尝试 学习
fatal error: jni.h: No such file or directory
Arduino实验三:继电器实验
力扣刷题之求两数之和
Unity获取canvas 下ui 在屏幕中的实际坐标
阿里资深专家打造从零开始学架构,含阿里内部技术栈PPT、PFD实战
[Dataset][VOC] Rat dataset voc format 3001 sheets
七夕之前,终于整出了带AI的美丽秘笈
阿里巴巴政委体系-第七章、阿里政委培育
PHP base notes - NO. 1
Postgresql源码(65)新快照体系Globalvis工作原理分析
爬虫之selenium
要想成为黑客,离不开这十大基础知识
盲僧发现了华点——教你如何使用API接口获取数据
PHP基础笔记-NO.2
APT级全面免杀与企业纵深防御体系的红蓝对抗
力扣刷题之有效的正方形(每日一题7/29)
【C语言学习笔记(六)】分支与跳转(if、else、continue、break、switch)