diff --git a/src/lib.rs b/src/lib.rs index 001e9d4..b6528ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ use std::thread; pub struct ThreadPool { - threads: Vec>, + workers: Vec, } impl ThreadPool { @@ -15,11 +15,13 @@ impl ThreadPool { pub fn new(size: usize) -> ThreadPool { assert!(size > 0); - let mut threads = Vec::with_capacity(size); + let mut workers = Vec::with_capacity(size); - for _ in 0..size {} + for id in 0..size { + workers.push(Worker::new(id)) + } - ThreadPool { threads } + ThreadPool { workers } } pub fn execute(&self, f: F) @@ -28,3 +30,15 @@ impl ThreadPool { { } } + +struct Worker { + id: usize, + thread: thread::JoinHandle<()>, +} + +impl Worker { + pub fn new(id: usize) -> Worker { + let thread = thread::spawn(|| {}); + Worker { id, thread } + } +}