From 8abbe904ebee076e50c36d29ae2359b8019ecd26 Mon Sep 17 00:00:00 2001 From: Unisko PENG Date: Mon, 3 Apr 2023 13:05:44 +0800 Subject: [PATCH] Update Ch20 --- hello/src/lib.rs | 1 + ...Project_Building_a_Multithreaded_Web_Server.md | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/hello/src/lib.rs b/hello/src/lib.rs index f0e1890..e27da1d 100644 --- a/hello/src/lib.rs +++ b/hello/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(warnings)] pub struct ThreadPool; impl ThreadPool { diff --git a/src/Ch20_Final_Project_Building_a_Multithreaded_Web_Server.md b/src/Ch20_Final_Project_Building_a_Multithreaded_Web_Server.md index 5a90937..5a295cd 100644 --- a/src/Ch20_Final_Project_Building_a_Multithreaded_Web_Server.md +++ b/src/Ch20_Final_Project_Building_a_Multithreaded_Web_Server.md @@ -570,7 +570,7 @@ fn main() { 如同咱们在第 16 章中所学到的,`thread::spawn` 讲创建出一个新线程,并于随后在新线程中,运行那个闭包中的代码。当咱们运行此代码,并在浏览器中加载 `/sleep`,随后在另外两个浏览器 Tab 页中加载 `/`,咱们就会看到到 `/` 的请求就不必等待 `/sleep` 请求完毕了。不过,如同咱们曾提到过的,因为咱们正不带任何限制地构造新线程,而最终将使系统不堪重负。 -#### 创建有限数目的线程 +#### 创建有限数目的线程 **Creating a Finite Number of Threads** @@ -670,3 +670,16 @@ impl ThreadPool { 下面来再次检查: ```console +$ cargo check + Checking hello v0.1.0 (/home/lenny.peng/rust-lang-zh_CN/hello) +error[E0599]: no method named `execute` found for struct `ThreadPool` in the current scope + --> src/main.rs:19:14 + | +19 | pool.execute(|| { + | ^^^^^^^ method not found in `ThreadPool` + +For more information about this error, try `rustc --explain E0599`. +error: could not compile `hello` due to previous error +``` + +现在的报错之所以出现,是因为在 `ThreadPool` 上咱们没有一个 `execute` 方法。回顾 ["创建有限数目的线程"](#creating-a-finite-number-of-threads) 小节到,咱们已决定咱们的线程池,应有一个类似与 `thread::spawn` 的接口。此外,