Skip to content

Commit 647b4cd

Browse files
committed
多线程核心更新
1 parent 28f00c2 commit 647b4cd

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

MD/Threadcore.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public final boolean compareAndSet(long expect, long update) {
3939

4040
其逻辑就是判断当前的值是否被更新过,是否等于 `current`,如果等于就说明没有更新过然后将当前的值更新为 `next`,如果不等于则返回`false` 进入循环,直到更新成功为止。
4141

42+
还有其中的 `get()` 方法也很关键,返回的是当前的值,当前值用了 `volatile` 关键词修饰,保证了内存可见性。
43+
44+
```java
45+
private volatile int value;
46+
```
47+
4248

4349
## 可见性
4450

0 commit comments

Comments
 (0)