当前位置:网站首页>Three concurrent features 1- visibility
Three concurrent features 1- visibility
2022-06-22 08:13:00 【Hide on jdk】
visibility : When a thread changes the value of a shared variable , Other threads can see the modified value
The bottom layer is how to ensure visibility ?
1. adopt volatile Keywords guarantee visibility .
2. adopt Memory barrier ensures visibility .
3. adopt synchronized Keywords guarantee visibility .
4. adopt Lock Guaranteed visibility .
5. adopt final Keywords guarantee visibility
How to interact data between main memory and working memory ?
adopt 8 Big atom operation :
lock( lock ): A variable acting on main memory , Identifies a variable as a thread exclusive state .
unlock( Unlock ): Operates on the main memory variable , Release a variable that is locked , Release
Later variables can be locked by other threads .
read( Read ): Operates on the main memory variable , Transfer a variable value from main memory to the thread's working memory
in , For subsequent load The action to use
load( load ): A variable acting on working memory , It is the read The operation puts the variable value obtained from the main memory
Into a copy of the variable in working memory
use( Use ): A variable acting on working memory , Pass the value of a variable in the working memory to the execution reference
Qing Dynasty , This is done whenever the vm gets a bytecode instruction that requires the value of the variable to be used .
assign( assignment ): A variable acting on working memory , It assigns a value received from the execution engine to
Working memory variables , This is done whenever the vm receives a bytecode instruction that assigns a value to a variable .
store( Storage ): A variable acting on working memory , Transfer the value of a variable in the working memory to the main
In the memory , For subsequent write The operation of .
write( write in ): A variable acting on main memory , It is the store Operate on the value of a variable from working memory
To a variable in main memory .
volatile Characteristics of
visibility : To a volatile Variable reading , Always see ( Arbitrary thread ) For this volatile Variable most
Write after .
Atomicity : For any single volatile Variable reading / It's atomic , But similar to volatile++ Such complex
The combination operation is not atomic
Orderliness : Yes volatile Various specific memory barriers are added before and after the read and write operations of modified variables to prohibit referring to
Reorder to ensure order
volatile stay hotspot The implementation of the
Bytecode interpreter implementation 
Conclusion :x86 In the processor lock Achieve the effect similar to memory barrier
Assembly level volatile The implementation of the
Add the following jvm Parameter visibility before viewing Demo Assembly instructions for
| ‐XX | : | +UnlockDiagnosticVMOptions | ‐XX | : | +PrintAssembly | ‐Xcomp |
边栏推荐
猜你喜欢

Idea reports an error "insufficient memory"

并发三大特性2-有序性

MySQL query group by 1055 is the simplest and most convenient way to solve the problem perfectly

【Oracle 数据库】奶妈式教程 day12 字符函数

Mt4/mql4 getting started to mastering EA tutorial lesson 5 - common functions of MQL language (V) - common functions of account information

Characteristics of industrial Internet

Note pad replaces all contents after a character in all lines
![[Oracle database] mammy tutorial day14 conversion function](/img/ef/c468316750c57212a067abd00a10e9.png)
[Oracle database] mammy tutorial day14 conversion function

mapTalks:基础操作与WMS/WMTS地图服务加载

IP address planning
随机推荐
Oracle gets the working day time between two dates
【Oracle 数据库】奶妈式教程 day12 字符函数
MySQL delete from and subquery as conditions
How to create an index
Summary of basic knowledge of Oracle database SQL statement III: data operation language (DQL)
[普通物理]波的能量与干涉
LVS Technology Practice
Concatenate the specified character at the end of a number in a string
Collections and arrays
Skills required for O & M automation?
Easyui数据表实现增删改
Thoughts on the construction of data analysis platform for small and medium-sized enterprises (I)
Stored procedures and functions of MySQL
Oracle execution plan analysis
模電實驗——實驗二 JFET共源極放大電路
Mt4/mql4 getting started to mastering EA tutorial lesson 8 - common functions of MQL language (VIII) - common time function
Detailed explanation of subnet mask
模板代码概述
On Fresnel phenomenon
JSON使用示例