Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c473df5

Browse files
committed
修订格式
1 parent 2b4a035 commit c473df5

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

‎7.三大性质总结:原子性、可见性以及有序性/三大性质总结:原子性、可见性以及有序性.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
原子性是指**一个操作是不可中断的,要么全部执行成功要么全部执行失败,有着"同生共死"的感觉**。及时在多个线程一起执行的时候,一个操作一旦开始,就不会被其他线程所干扰。我们先来看看哪些是原子操作,哪些不是原子操作,有一个直观的印象:
66

77
> int a = 10; //1
8+
>
89
> a++; //2
10+
>
911
> int b=a; //3
12+
>
1013
> a = a+1; //4
1114
1215
上面这四个语句中只**有第1个语句是原子操作**,将10赋值给线程工作内存的变量a,而语句2(a++),实际上包含了三个操作:1. 读取变量a的值;2:对a进行加一的操作;3.将计算后的值再赋值给变量a,而这三个操作无法构成原子操作。对语句3,4的分析同理可得这两条语句不具备原子性。当然,[java内存模型](https://juejin.im/post/5ae6d309518825673123fd0e)中定义了8中操作都是原子的,不可再分的。

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /