From 24f0ca7de186ca4044a8023377c188dd4ed1eb90 Mon Sep 17 00:00:00 2001 From: Shautvast Date: Mon, 9 Feb 2026 20:09:57 +0100 Subject: [PATCH] #15 threadpool #4 --- src/main.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 456e722..d07c1cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,19 @@ use std::thread; static GET: &'static [u8] = b"GET / HTTP/1.1\r\n"; pub struct ThreadPool { - threads: Vec>, + workers: Vec, +} + +struct Worker{ + id: usize, + thread: thread::JoinHandle<()>, +} + +impl Worker { + fn new(id: usize) -> Worker { + let thread = thread::spawn(|| {}); + Worker { id, thread } + } } impl ThreadPool { @@ -17,13 +29,13 @@ impl ThreadPool { /// The `new` function panics if the size is zero pub fn new(size: usize) -> Self { assert!(size > 0); - let threads = Vec::with_capacity(size); - for _ in 0..size { - + let mut workers = Vec::with_capacity(size); + for id in 0..size { + workers.push(Worker::new(id)) } - Self {threads} + Self {workers} } - + } fn main() -> std::io::Result<()> {