> For the complete documentation index, see [llms.txt](https://fengmuzi2003.gitbook.io/csapp3e/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fengmuzi2003.gitbook.io/csapp3e/di-12-zhang-bing-fa-bian-cheng.md).

# 第12章：并发编程

## [视频解说](https://www.bilibili.com/video/BV1RK4y1R7Kf?p=12)

## 导读

处理器发展的趋势：多核时代早已到来！免费的午餐已经结束了！

参考文章（Herb Sutter）：[The Free Lunch Is Over: A Fundamental Turn Toward Concurrency in Software](http://www.gotw.ca/publications/concurrency-ddj.htm)

![](/files/-Mb_18hVbbEG2x_KH-n8)

多核处理器成为上述变革的主流解決方案，想要压榨出更多的处理器效能，软件必须跟上硬件的设计！

## 学习方式

[CMU教授的视频教程 - Lecture23：并发编程](https://www.bilibili.com/video/BV1a54y1k7YE?p=29)

[CMU教授的视频教程 - Lecture24：同步（基础）](https://www.bilibili.com/video/BV1a54y1k7YE?p=30)

[CMU教授的视频教程 - Lecture25：同步（进阶）](https://www.bilibili.com/video/BV1a54y1k7YE?p=31)

[CMU教授的视频教程 - Lecture26：线程级并行](https://www.bilibili.com/video/BV1a54y1k7YE?p=32)

## 重点解读

[【大佬讲座】谷歌大神 Rob Pike：并发 vs 并行 (傻傻分不清楚？)](https://www.bilibili.com/video/BV1EN411o7FY/)

Concurrency （并发）指程序架构，将程序拆成多个可独立运行的部分，不一定要同时运行，Parallelism（并行） 指程序执行，同时执行多个程序。

Concurrency 可能会用到 Parallelism，但不一定要用 Parallelism 才能实现 Concurrency。在 Concurrent 中，工作可拆分成「独立执行」的部份，于是「可以」让很多事情一起做，但「不一定」要真的同时做，参见下图。

![](/files/-Mb_8rPEKSwKYp6bHv-6)

以Rob Pike的地鼠烧书为例：1） 如何分割各个地鼠负责的工作， 2）各个地鼠如何进行高效的协调与沟通

![](/files/-Mb_FD1xMZ4FrgkZ_jnO)

那么我们究竟应该如何创建一个并行程序呢？以下流程图示取自CMU：15-418 并行计算架构与编程。

![](/files/-MbdwBz1e5u_auLO2PVN)

## 延伸阅读

* 卡内基梅隆大学：[并行计算架构与编程 (15-418 / 15-618)](https://www.bilibili.com/video/BV1aa4y1s7EH/)
* 伊利诺伊大学：[异构并行编程（胡文美教授）- 重点讲解CUDA编程](https://www.bilibili.com/video/BV1z541137iG/)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fengmuzi2003.gitbook.io/csapp3e/di-12-zhang-bing-fa-bian-cheng.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
