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

How does MySQL permanently support Chinese input once and for all?

WEB 渗透之RCE

2022年最新的Android面试大厂必考174题(附带详细答案)

爬虫之selenium

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

学弟:我适不适合转行做软件测试?

Zhong Hua, senior architect of Ali: China-Taiwan strategic thinking and architecture practice; including internal implementation manual

Chrome浏览器开发新截图工具,安全浏览器截图方法

高等数学---第十章无穷级数---常数项级数

阿里巴巴政委体系-第八章、阿里政委工作方法论
随机推荐
VsCode preview Geojson data
七夕之前,终于整出了带AI的美丽秘笈
excel写入不完全sheet.append方法(openpyxl)
基于ck+redash构建MySQL慢日志+审计日志展示平台
分享即时通讯开发之WebSocket:概念、原理、易错常识、动手实践
if/else或switch替换为Enum
MySQL详细学习教程(建议收藏)
ROS仿真环境搭建
【微信小程序】NFC 标签打开小程序
要想成为黑客,离不开这十大基础知识
基于DMS的数仓智能运维服务,知多少?
WEB 渗透之SSRF
PreFixSum前缀和
选出表中的中位数记录[构造左右边界 || 问题转换]
【ORACLE】什么时候ROWNUM等于0和ROWNUM小于0,两个条件不等价?
【C语言学习笔记(五)】while循环与for循环
Shell编程案例
POJ 3041 Asteroids(最大匹配数=最小点覆盖)
盲僧发现了华点——教你如何使用API接口获取数据
dd命令:用于读取、转换并输出数据