From fefe3ef522b2a88fe3db946f11962d27c00f2b5a Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Mon, 20 Jan 2020 14:34:46 -0500 Subject: [PATCH 1/2] Update references to Listing 20-21 to ref 20-20 instead The listing 20-21 referenced in these places was removed in 37a17ef40ccee85b28963cfe8d83ff8d66bd7717. --- src/ch20-03-graceful-shutdown-and-cleanup.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch20-03-graceful-shutdown-and-cleanup.md b/src/ch20-03-graceful-shutdown-and-cleanup.md index c24e463340..b9812c68ea 100644 --- a/src/ch20-03-graceful-shutdown-and-cleanup.md +++ b/src/ch20-03-graceful-shutdown-and-cleanup.md @@ -1,6 +1,6 @@ ## Graceful Shutdown and Cleanup -The code in Listing 20-21 is responding to requests asynchronously through the +The code in Listing 20-20 is responding to requests asynchronously through the use of a thread pool, as we intended. We get some warnings about the `workers`, `id`, and `thread` fields that we’re not using in a direct way that reminds us we’re not cleaning up anything. When we use the less elegant Date: Mon, 20 Jan 2020 14:38:04 -0500 Subject: [PATCH 2/2] Renumber listings following removed listing Listing 20-21 was removed in 37a17ef40ccee85b28963cfe8d83ff8d66bd7717, and listing 20-22 was renumbered because it's in the same file as 20-21 was, but the rest of the listings in chapter 20 weren't renumbered. --- src/ch20-03-graceful-shutdown-and-cleanup.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ch20-03-graceful-shutdown-and-cleanup.md b/src/ch20-03-graceful-shutdown-and-cleanup.md index b9812c68ea..174378b935 100644 --- a/src/ch20-03-graceful-shutdown-and-cleanup.md +++ b/src/ch20-03-graceful-shutdown-and-cleanup.md @@ -18,7 +18,7 @@ accept only two requests before gracefully shutting down its thread pool. Let’s start with implementing `Drop` on our thread pool. When the pool is dropped, our threads should all join to make sure they finish their work. -Listing 20-23 shows a first attempt at a `Drop` implementation; this code won’t +Listing 20-22 shows a first attempt at a `Drop` implementation; this code won’t quite work yet. Filename: src/lib.rs @@ -35,7 +35,7 @@ impl Drop for ThreadPool { } ``` -Listing 20-23: Joining each thread when the thread pool +Listing 20-22: Joining each thread when the thread pool goes out of scope First, we loop through each of the thread pool `workers`. We use `&mut` for @@ -178,7 +178,7 @@ thread should run, or it will be a `Terminate` variant that will cause the thread to exit its loop and stop. We need to adjust the channel to use values of type `Message` rather than type -`Job`, as shown in Listing 20-24. +`Job`, as shown in Listing 20-23. Filename: src/lib.rs @@ -236,7 +236,7 @@ impl Worker { } ``` -Listing 20-24: Sending and receiving `Message` values and +Listing 20-23: Sending and receiving `Message` values and exiting the loop if a `Worker` receives `Message::Terminate` To incorporate the `Message` enum, we need to change `Job` to `Message` in two @@ -250,7 +250,7 @@ is received. With these changes, the code will compile and continue to function in the same way as it did after Listing 20-20. But we’ll get a warning because we aren’t creating any messages of the `Terminate` variety. Let’s fix this warning by -changing our `Drop` implementation to look like Listing 20-25. +changing our `Drop` implementation to look like Listing 20-24. Filename: src/lib.rs @@ -276,7 +276,7 @@ impl Drop for ThreadPool { } ``` -Listing 20-25: Sending `Message::Terminate` to the +Listing 20-24: Sending `Message::Terminate` to the workers before calling `join` on each worker thread We’re now iterating over the workers twice: once to send one `Terminate` @@ -302,7 +302,7 @@ messages as there are workers, each worker will receive a terminate message before `join` is called on its thread. To see this code in action, let’s modify `main` to accept only two requests -before gracefully shutting down the server, as shown in Listing 20-26. +before gracefully shutting down the server, as shown in Listing 20-25. Filename: src/bin/main.rs @@ -323,7 +323,7 @@ fn main() { } ``` -Listing 20-26: Shut down the server after serving two +Listing 20-25: Shut down the server after serving two requests by exiting the loop You wouldn’t want a real-world web server to shut down after serving only two