Skip to content

Commit eaded3e

Browse files
committed
txs auto checkin
1 parent ded6de3 commit eaded3e

File tree

1 file changed

+82
-1
lines changed

1 file changed

+82
-1
lines changed

rust.tex

+82-1
Original file line numberDiff line numberDiff line change
@@ -3233,9 +3233,90 @@ \section{Multithread Web Server}
32333233
32343234
\begin{frame}[fragile]
32353235
\frametitle{Improving Throughput with a Thread Pool}
3236-
\inputminted{rust}{./code/http2.rs}
3236+
A thread pool is a group of spawned threads that are waiting and ready to handle a task. When the program receives a new task, it assigns one of the threads in the pool to the task, and that thread will process the task. The remaining threads in the pool are available to handle any other tasks that come in while the first thread is processing. When the first thread is done processing its task, it’s returned to the pool of idle threads, ready to handle a new task. A thread pool allows you to process connections concurrently, increasing the throughput of your server.
3237+
\end{frame}
3238+
3239+
3240+
\begin{frame}[fragile]
3241+
\frametitle{Creating a Finite Number of Threads}
3242+
\inputminted{rust}{./code/http3.rs}
3243+
\end{frame}
3244+
3245+
\begin{frame}[fragile]
3246+
\frametitle{Creating a Finite Number of Threads(2)}
3247+
\inputminted{rust}{./code/http4.rs}
3248+
\end{frame}
3249+
3250+
\begin{frame}[fragile]
3251+
\frametitle{Creating a Finite Number of Threads(3)}
3252+
\inputminted[fontsize=\scriptsize]{rust}{./code/http5.rs}
3253+
\end{frame}
3254+
3255+
3256+
\begin{frame}[fragile]
3257+
\frametitle{A Worker Struct Responsible for Sending Code from the ThreadPool to a Thread}
3258+
\inputminted[fontsize=\scriptsize]{rust}{./code/http6.rs}
3259+
\end{frame}
3260+
3261+
\begin{frame}[fragile]
3262+
\frametitle{A Worker Struct Responsible for Sending Code from the ThreadPool to a Thread(2)}
3263+
\inputminted[fontsize=\scriptsize]{rust}{./code/http7.rs}
3264+
\end{frame}
3265+
3266+
\begin{frame}[fragile]
3267+
\frametitle{Sending Requests to Threads via Channels}
3268+
\inputminted[fontsize=\fontsize{8.5}{8.5}]{rust}{./code/http8.rs}
3269+
\end{frame}
3270+
3271+
\begin{frame}[fragile]
3272+
\frametitle{Sending Requests to Threads via Channels}
3273+
\inputminted[fontsize=\fontsize{8.5}{8.5}]{rust}{./code/http8.rs}
3274+
\end{frame}
3275+
3276+
\begin{frame}[fragile]
3277+
\frametitle{Sending Requests to Threads via Channels(2)}
3278+
\inputminted[fontsize=\fontsize{8.5}{8.5}]{rust}{./code/http9.rs}
32373279
\end{frame}
32383280
3281+
\begin{frame}[fragile]
3282+
\frametitle{Sending Requests to Threads via Channels(3)}
3283+
\inputminted[fontsize=\fontsize{8.5}{8.5}]{rust}{./code/http10.rs}
3284+
\end{frame}
3285+
3286+
3287+
\begin{frame}[fragile]
3288+
\frametitle{Implementing the execute Method}
3289+
\inputminted[fontsize=\scriptsize]{rust}{./code/http11.rs}
3290+
\end{frame}
3291+
3292+
\begin{frame}[fragile]
3293+
\frametitle{Implementing the execute Method(2)}
3294+
\inputminted[fontsize=\scriptsize]{rust}{./code/http12.rs}
3295+
\end{frame}
3296+
3297+
\begin{frame}[fragile]
3298+
\frametitle{Graceful Shutdown and Cleanup, Implementing the Drop Trait on ThreadPool}
3299+
\inputminted[fontsize=\scriptsize]{rust}{./code/http14.rs}
3300+
3301+
\scriptsize
3302+
The error tells us we can’t call join because we only have a mutable borrow of each worker and join takes ownership of its argument. To solve this issue, we need to move the thread out of the Worker instance that owns thread so join can consume the thread. If Worker holds an \mintinline{rust}|Option<thread::JoinHandle<()>>| instead, we can call the \mintinline{rust}|take| method on the Option to move the value out of the Some variant and leave a None variant in its place. In other words, a Worker that is running will have a Some variant in thread, and when we want to clean up a Worker, we’ll replace Some with None so the Worker doesn’t have a thread to run.
3303+
3304+
\end{frame}
3305+
3306+
3307+
\begin{frame}[fragile]
3308+
\frametitle{Graceful Shutdown and Cleanup, Implementing the Drop Trait on ThreadPool(2)}
3309+
\inputminted[fontsize=\scriptsize]{rust}{./code/http15.rs}
3310+
\end{frame}
3311+
3312+
3313+
3314+
\begin{frame}[fragile]
3315+
\frametitle{Signaling to the Threads to Stop Listening for Jobs}
3316+
\inputminted[fontsize=\scriptsize]{rust}{./code/http15.rs}
3317+
\end{frame}
3318+
3319+
32393320
\section{Tokio}
32403321
32413322
\section*{Acknowledgement}

0 commit comments

Comments
 (0)