Skip to content

Commit f12fa72

Browse files
committed
1. 修改 第二章 std::jthread 一节中有关线程停止和 pthread_cancel 的对比描述
2. 修改第四章“C++20信号量”一节中内容,强调 `acquire`、`release` 是原子的减少与增加计数 #12
1 parent 920f1ae commit f12fa72

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Diff for: md/02使用线程.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ stop_source _Ssource;
899899
900900
首先要明确,C++ 的 `std::jthread` 提供的线程停止功能并不同于常见的 POSIX 函数 [`pthread_cancel`](https://pubs.opengroup.org/onlinepubs/9699919799/)`pthread_cancel` 是一种发送取消请求的函数,但并不是强制性的线程终止方式。目标线程的可取消性状态和类型决定了取消何时生效。当取消被执行时,进行清理和终止线程[^2]
901901
902-
`std::jthread` 所谓的线程停止只是一种基于用户代码的控制机制,而不是一种强制性的线程终止。使用 `std::stop_source`[`std::stop_token`](https://zh.cppreference.com/w/cpp/thread/stop_token) 提供了一种优雅地请求线程停止的方式,**但实际上停止的决定和实现都由用户代码来完成**
902+
`std::jthread` 所谓的线程停止只是一种**基于用户代码的控制机制**,而不是一种与操作系统系统有关系的线程终止。使用 `std::stop_source`[`std::stop_token`](https://zh.cppreference.com/w/cpp/thread/stop_token) 提供了一种优雅地请求线程停止的方式,**但实际上停止的决定和实现都由用户代码来完成**
903903
904904
```cpp
905905
using namespace std::literals::chrono_literals;

Diff for: md/04同步操作.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ int main() {
11711171
[主] 获得信号
11721172
```
11731173

1174-
[`acquire`](https://zh.cppreference.com/w/cpp/thread/counting_semaphore/acquire) 函数就是我们先前说的“*等待*”(减少计数),`release` 函数就是"释放"(增加计数)。
1174+
[`acquire`](https://zh.cppreference.com/w/cpp/thread/counting_semaphore/acquire) 函数就是我们先前说的“*等待*”(**原子**地减少计数),[`release`](https://zh.cppreference.com/w/cpp/thread/counting_semaphore/release) 函数就是"释放"(**原子**地增加计数)。
11751175

11761176
---
11771177

0 commit comments

Comments
 (0)