Skip to content

Commit af9c708

Browse files
committed
fix
1 parent 0ff7280 commit af9c708

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

memory_barrier.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,24 @@ Invalidate Queues:
157157

158158
从结果上来讲,memory barrier 是必须的。一个 store barrier 会把 store buffer flush 掉,确保所有的写操作都被应用到 CPU 的 cache。一个 read barrier 会把 invalidation queue flush 掉,也就确保了其它 CPU 的写入对执行 flush 操作的当前这个 CPU 可见。再进一步,MMU 没有办法扫描 store buffer,会导致类似的问题。这种效果对于单线程处理器来说已经是会发生的了。
159159

160+
161+
## barrier
162+
163+
从功能上来讲,barrier 有四种:
164+
165+
|||
166+
|-|-|
167+
|#LoadLoad|#LoadStore|
168+
|#StoreLoad|#StoreStore|
169+
160170
## lfence, sfence, mfence
161171

162172
https://stackoverflow.com/questions/27595595/when-are-x86-lfence-sfence-and-mfence-instructions-required
163173

164-
## acquire/release 抽象
174+
## acquire/release 语义
165175

166176
https://preshing.com/20130922/acquire-and-release-fences/
167177

168-
## write barrier, read barrier
169178

170179
## memory order
171180

@@ -237,6 +246,8 @@ P2 中的指令和 snippet 1 交错执行时,可能产生的结果是:111101
237246

238247
P2 中的指令和 snippet 2 交错执行时,可能产生的结果是:11100000…​
239248

249+
多核心下,编译器对代码的优化理论上就是重排。
250+
240251
## atomic/lock 操作成本 in Go
241252

242253
```go

0 commit comments

Comments
 (0)