Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c2391e8

Browse files
committed
修改第三章与第四章的小错误
1 parent 97f5b6b commit c2391e8

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

‎md/03共享数据.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ struct X{
860860
861861
void f(){
862862
X* p = new X{ 1 }; // 存在数据竞争
863-
delete x;
863+
delete p;
864864
}
865865
```
866866

‎md/04同步操作.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ C++ 标准库有两种 future,都声明在 [`<future>`](https://zh.cppreferenc
281281

282282
### 创建异步任务获取返回值
283283

284-
假设需要执行一个耗时任务并获取其返回值,但是并不急切的需要它。那么久可以启动新线程计算,然而 `std::thread` 没提供直接接收返回值的机制。所以我们可以使用 [`std::async`](https://zh.cppreference.com/w/cpp/thread/async) 函数模板。
284+
假设需要执行一个耗时任务并获取其返回值,但是并不急切的需要它。那么就可以启动新线程计算,然而 `std::thread` 没提供直接接收返回值的机制。所以我们可以使用 [`std::async`](https://zh.cppreference.com/w/cpp/thread/async) 函数模板。
285285

286286
使用 `std::async` 启动一个异步任务,它会返回一个 `std::future` 对象,这个对象和任务关联,将持有最终计算出来的结果。当需要这个值的时候,只需要调用 [`get()`](https://zh.cppreference.com/w/cpp/thread/future/get) 成员函数,就会阻塞直到 `future` 为就绪为止,返回执行结果。
287287

@@ -291,7 +291,7 @@ C++ 标准库有两种 future,都声明在 [`<future>`](https://zh.cppreferenc
291291
#include <future>
292292

293293
int task(int n){
294-
std::cout << "异步任务 ID: " << std::this_thread::get_id << '\n';
294+
std::cout << "异步任务 ID: " << std::this_thread::get_id() << '\n';
295295
return n * n;
296296
}
297297

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /