From e4211e27bf07e0ab50f6b134c08a6b094cf801cc Mon Sep 17 00:00:00 2001 From: Shautvast Date: Mon, 9 Feb 2026 20:24:19 +0100 Subject: [PATCH] #17 threadpool #6 --- src/main.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index b1b472d..10c80c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,23 +6,25 @@ use std::{sync, thread}; static GET: &'static [u8] = b"GET / HTTP/1.1\r\n"; -pub struct ThreadPool { - workers: Vec, - sender: mpsc::Sender, -} - struct Worker { id: usize, thread: thread::JoinHandle<()>, } impl Worker { - fn new(id: usize) -> Worker { - let thread = thread::spawn(|| {}); + fn new(id: usize, receiver: mpsc::Receiver) -> Worker { + let thread = thread::spawn(|| { + receiver; + }); Worker { id, thread } } } +pub struct ThreadPool { + workers: Vec, + sender: mpsc::Sender, +} + impl ThreadPool { /// Create a new ThreadPool /// @@ -34,7 +36,7 @@ impl ThreadPool { let mut workers = Vec::with_capacity(size); let (sender, receiver) = mpsc::channel(); for id in 0..size { - workers.push(Worker::new(id)) + workers.push(Worker::new(id, receiver)) } Self { workers, sender } }