Skip to content

Commit

Permalink
Merge pull request #781 from LyonRust/patch-1
Browse files Browse the repository at this point in the history
Update ch20-02-multithreaded.md
  • Loading branch information
KaiserY authored Mar 10, 2024
2 parents 24d0869 + a33e554 commit ed16d5a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/ch20-02-multithreaded.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ pub fn spawn<F, T>(f: F) -> JoinHandle<T>
#### `new` 中验证池中线程数量

这里仍然存在警告是因为其并没有对 `new``execute` 的参数做任何操作。让我们用期望的行为来实现这些函数。以考虑 `new` 作为开始。之前选择使用无符号类型作为 `size` 参数的类型,因为线程数为负的线程池没有意义。然而,线程数为零的线程池同样没有意义,不过零是一个完全有效的 `u32` 值。让我们增加在返回 `ThreadPool` 实例之前检查 `size` 是否大于零的代码,并使用 `assert!` 宏在得到零时 panic,如示例 20-13 所示:
这里仍然存在警告是因为其并没有对 `new``execute` 的参数做任何操作。让我们用期望的行为来实现这些函数。以考虑 `new` 作为开始。之前选择使用无符号类型作为 `size` 参数的类型,因为线程数为负的线程池没有意义。然而,线程数为零的线程池同样没有意义,不过零是一个完全有效的 `usize` 值。让我们增加在返回 `ThreadPool` 实例之前检查 `size` 是否大于零的代码,并使用 `assert!` 宏在得到零时 panic,如示例 20-13 所示:

<span class="filename">文件名:src/lib.rs</span>

Expand Down

0 comments on commit ed16d5a

Please sign in to comment.