Skip to content

Commit 486908a

Browse files
committed
book: motivate §7.1 with why standardized threading matters
§7.1 dove straight into the std::thread API; add a lead explaining that pre-C++11 there was no standard threading (only platform pthread/Windows APIs), so C++11's thread library is what makes portable concurrency possible.
1 parent 198adb8 commit 486908a

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

book/en-us/07-thread.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ order: 7
1212

1313
*(since C++11)*
1414

15+
Before C++11, the C++ standard library had no notion of threads at all: writing concurrent code meant reaching for platform-specific APIs such as POSIX `pthread` or the Windows thread API, which made that code hard to port. C++11 brought threading into the language standard for the first time, so the same concurrent code now builds across platforms.
16+
1517
`std::thread` is used to create an execution thread instance, so it is the basis for all concurrent programming. It needs to include the `<thread>` header file when using it.
1618
It provides a number of basic thread operations, such as `get_id()` to get the thread ID of the thread being created, use `join()` to join a thread, etc., for example:
1719

book/zh-cn/07-thread.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ order: 7
1212

1313
*(C++11)*
1414

15+
在 C++11 之前,C++ 标准库根本没有线程的概念:要编写并发代码,只能依赖平台特定的 API(如 POSIX 的 `pthread` 或 Windows 线程 API),这让代码难以跨平台移植。C++11 首次把线程纳入语言标准,使同一份并发代码得以跨平台构建。
16+
1517
`std::thread` 用于创建一个执行的线程实例,所以它是一切并发编程的基础,使用时需要包含 `<thread>` 头文件,
1618
它提供了很多基本的线程操作,例如 `get_id()` 来获取所创建线程的线程 ID,使用 `join()` 来等待一个线程结束(与该线程汇合)等等,例如:
1719

0 commit comments

Comments
 (0)