当前位置:网站首页>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.
边栏推荐
猜你喜欢
MySQL 啥时候用表锁,啥时候用行锁?这些你都应该知道吧
CC2530_ZigBee+华为云IOT:设计一套属于自己的冷链采集系统
微信小程序分享功能
图像超分——Real-ESRGAN快速上手
开发即时通讯到底需要什么样的技术,需要多久的时间
Selenium of reptiles
Don't look down upon the WebSocket!Long connection, stateful, two-way, full-duplex king is Fried
Compose原理-compose中是如何实现事件分法的
MySQL超详细安装教程 手把手教你安装MySQL到使用MySQL 最简单的MySQL安装方式,这种方式装,卸载也简单
PHP基础笔记-NO.1
随机推荐
【C语言学习笔记(五)】while循环与for循环
OneNote 教程,如何在 OneNote 中设置页面格式?
讯方实训云平台——加速教育高质量发展的“数字底座”!
【微信小程序】NFC 标签打开小程序
阿里二面:多线程间的通信方式有几种?举例说明
Radondb mysql installation problems
6000 字+,帮你搞懂互联网架构演变历程!
APT级全面免杀与企业纵深防御体系的红蓝对抗
MySQL超详细安装教程 手把手教你安装MySQL到使用MySQL 最简单的MySQL安装方式,这种方式装,卸载也简单
Selenium of reptiles
使用安全浏览器将网页保存为pdf的方法步骤
MySQL——增删改查进阶
PHP基础笔记-NO.2
力扣刷题之合并两个有序数组
阿里资深专家打造从零开始学架构,含阿里内部技术栈PPT、PFD实战
go语言实现导出string字符串到文件中
货比四家 version tb1.63
Zhong Hua, senior architect of Ali: China-Taiwan strategic thinking and architecture practice; including internal implementation manual
When does MySQL use table locks and when to use row locks?You should know this
【HCIP】MPLS实验