Skip to content

Commit

Permalink
feat: add more comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Serein207 committed Dec 26, 2023
1 parent 290a405 commit d1378e9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions blog/posts/2023-12-25-cpp-concurrency.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ authors:
- Serein
---

聊聊C++并发编程中比较高级的无锁编程。

## 内存模型基础

### 对象和内存位置
Expand All @@ -18,6 +20,8 @@ authors:
3. 基本类型都有确定的内存位置(无论类型大小如何,即使他们是相邻的,或是数组的一部分)。
4. 相邻位域是相同内存中的一部分。

<!-- more -->

### 对象、内存位置和并发

为了避免条件竞争,两个线程就需要一定的执行顺序。第一种方式,如第3章所述,使用互斥量来确定访问的顺序;当同一互斥量在两个线程同时访问前被锁住,那么在同一时间内就只有一个线程能够访问到对应的内存位置,所以后一个访问必须在前一个访问之后。另一种是使用原子操作决定两个线程的访问顺序。当多于两个线程访问同一个内存地址时,对每个访问这都需要定义一个顺序。如果不规定两个不同线程对同一内存地址访问的顺序,那么访问就不是原子的;并且,当两个线程都是“writer”时,就会产生数据竞争和未定义行为。
Expand Down

0 comments on commit d1378e9

Please sign in to comment.