From bbf889e72efdcfc3987beac934bbb8183ea58c6e Mon Sep 17 00:00:00 2001 From: Shautvast Date: Mon, 9 Feb 2026 20:13:08 +0100 Subject: [PATCH] #16 threadpool #5 --- src/main.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index d07c1cb..b1b472d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,17 @@ use log::info; use std::io::{Read, Write}; use std::net::{TcpListener, TcpStream}; -use std::thread; +use std::sync::mpsc; +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{ +struct Worker { id: usize, thread: thread::JoinHandle<()>, } @@ -27,17 +29,19 @@ impl ThreadPool { /// # Panics /// /// The `new` function panics if the size is zero - pub fn new(size: usize) -> Self { + pub fn new(size: usize) -> Self { assert!(size > 0); let mut workers = Vec::with_capacity(size); + let (sender, receiver) = mpsc::channel(); for id in 0..size { workers.push(Worker::new(id)) } - Self {workers} + Self { workers, sender } } - } +struct Job {} + fn main() -> std::io::Result<()> { env_logger::init(); let listener = TcpListener::bind("127.0.0.1:7878")?;