当前位置:网站首页>指令重排、happens-before、as-if-serial
指令重排、happens-before、as-if-serial
2022-07-28 23:43:00 【SnnnSn~】
指令重排是有一定限制的,有两个规则:happens-before、as-if-serial来约束。
目录
一. happens-before
1 定义
- 如果 操作A happens-before B,那么A 的执行结果将对 B 可见,而且A的执行顺序必须在B之前。
- 两个操作之间存在happens-before关系,并不意味着Java平台的具体实现必须要按照 happens-before关系指定的顺序来执⾏。如果重排序之后的执⾏结果,与按happens-before 关系来执⾏的结果⼀致,则指令可以重排序。
2.理解
站在程序员角度:为编程人员提供了一个类似强内存的内存结构,方便编程。
站在编辑器和处理器厂商:在不影响正确结果的前提下,可以让编辑器和处理器厂商尽情优化。
3.具体规则
- 程序顺序规则:一个线程的每个操作,happens-before于该线程中的任意后续操作。
- 监视器锁规则:对一个锁的解锁,happens-before于随后对这个锁的加锁。
- volatile变量规则:对一个volatile域的写,happens-before于任意后续对这个volatile域的读。
- 传递性:如果A happens-before B,且B happens-before C,那么A happens-before C。
- start()规则:如果线程A执行操作ThreadB.start()(启动线程B),那么线程A的ThreadB.start()操作happens-before于线程B中的任何操作。
- join()规则:如果线程A执行ThreadB.join()并成功返回,则B中的任何操作应该happens-before于线程A从ThreadB.join()操作成功返回。
二.as-if-serial规则
as-if-serial语义的意思指:不管怎么重排序(编译器和处理器为了提高并行度),(单线程)程序的执行结果不能被改变。编译器,runtime 和处理器都必须遵守as-if-serial语义。
为了遵守as-if-serial语义,编译器和处理器不会对存在数据依赖关系的操作做重排序,因为这种重排序会改变执行结果。但是,如果操作之间不存在数据依赖关系,这些操作可能被编译器和处理器重排序。
边栏推荐
- SurfaceControl和SurfaceFlinger通信
- [Commons lang3 topic] 004- numberutils topic
- 快手重点整治搬运、洗稿等方式的养号行为,自媒体平台如何净化内容生态
- DDD领域驱动设计如何进行工程化落地
- Cloud function realizes website automatic check-in configuration details [web function /nodejs/cookie]
- 关于ThreadPool的一些注意事项
- JWT token related configuration (global configuration identity authentication rewrites authenticate method)
- B-tree~
- Implement Lmax disruptor queue from scratch (VI) analysis of the principle of disruptor solving pseudo sharing and consumers' elegant stopping
- B- 树 ~
猜你喜欢
Depth first search (DFS) and its matlab code

Summary of preprocessing methods for time series data
![[AD learning] the course of PCB drawing in this marine vehicle competition](/img/37/211a0557848f6922fda7a69a114923.png)
[AD learning] the course of PCB drawing in this marine vehicle competition

QT静态编译程序(Mingw编译)

DRF - web development mode, API interface, API interface testing tool, restful specification, serialization and deserialization, DRF installation and use

Relying on cloud business to support revenue growth alone, is Microsoft still overvalued?

SystemVerilog-连接和复制运算符

iNFTnews | 元宇宙购物体验将成为吸引消费者的一大利器

Consumer unit 消费单元

Huawei releases harmonyos 3.0, taking another step towards "Internet of all things"
随机推荐
zabbix部署及监控
Implement Lmax disruptor queue from scratch (VI) analysis of the principle of disruptor solving pseudo sharing and consumers' elegant stopping
【目标检测】YOLOR理论简介+实践测试VisDrone数据集
第二轮1000个Okaleido Tiger,再次登录Binance NFT 1小时售罄
追踪伦敦银实时行情的方法有哪些?
Andriod6.0 low power mode (turn off WiFi, Bluetooth, GPS, screen brightness, etc.)
机器学习 | MATLAB实现RBF径向基神经网络newrbe参数设定
Station B "crashed" from beginning to end 2021.07.13 we collapsed like this (Reprint)
[untitled]
Execute immediate simple sample set (DML)
mysql时间按小时格式化_mysql时间格式化,按时间段查询的MySQL语句[通俗易懂]
[network security] complete the blacklist and whitelist functions of server firewall through iptables and ipset
小程序毕设作品之微信校园浴室预约小程序毕业设计成品(5)任务书
Yield Guild Games:这一年的总结与未来展望
Summary of preprocessing methods for time series data
Charles -- 从0-1教你如何使用抓包工具
day8
华为发布HarmonyOS 3.0,向“万物互联”再迈一步
NFT 项目的 7 种市场营销策略
(20211130更新)关于jupyter notebook的下载安装及自己的配置、主题