当前位置:网站首页>指令重排、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语义,编译器和处理器不会对存在数据依赖关系的操作做重排序,因为这种重排序会改变执行结果。但是,如果操作之间不存在数据依赖关系,这些操作可能被编译器和处理器重排序。
边栏推荐
- Some operations of Ubuntu remote server configuration database (unable to locate package MySQL server, steps of installing mysql, unable to enter password when logging in MySQL)
- Android必备的面试技能(含面试题和学习资料)
- 【commons-lang3专题】004- NumberUtils 专题
- JWT token related configuration (global configuration identity authentication rewrites authenticate method)
- I don't recommend you use Select*
- C语言括号匹配(栈括号匹配c语言)
- [network security] complete the blacklist and whitelist functions of server firewall through iptables and ipset
- The method of tracking the real-time market of London Silver
- Talk about the cross end technical scheme
- 小程序毕设作品之微信校园浴室预约小程序毕业设计成品(8)毕业设计论文模板
猜你喜欢

Jupyter notebook中5个有趣的魔法命令

JWT token related configuration (global configuration identity authentication rewrites authenticate method)

Necessary interview skills for Android (including interview questions and learning materials)

Wechat campus bathroom reservation applet graduation design finished product (5) assignment

Data warehouse construction - ads floor

The method of tracking the real-time market of London Silver

Error reporting: when the browser clicks the modify add button, there is no response and no error reporting. Solution
![[raspberry pie] how does the windows computer connect with raspberry pie](/img/d6/42685bbc4e4af757867442b63ce9c8.png)
[raspberry pie] how does the windows computer connect with raspberry pie

用CDO进行nc数据的不规则裁剪

【Web开发】Flask框架基础知识
随机推荐
用CDO进行nc数据的不规则裁剪
Data warehouse construction - DWT floor
Isolation level of MySQL, possible problems (dirty reading, unrepeatable reading, phantom reading) and their solutions
直流无刷电机控制器(换电机霍尔收费多少)
新一代超安全蜂窝电池,思皓爱跑上市,13.99万起售
B+ tree~
【commons-lang3专题】003- RandomStringUtils 专题
【Web开发】Flask框架基础知识
将Word中的表格以图片形式复制到微信发送
面试突击69:TCP 可靠吗?为什么?
day8
[Commons lang3 topic] 001 stringutils topic
Seven marketing strategies of NFT project
保护性拷贝&无状态
【树莓派】widows电脑如何与树莓派连接
【无标题】
Definition of double linked list~
SystemVerilog-连接和复制运算符
Depth first search (DFS) and its matlab code
Requestvideoframecallback() simple instance