diff --git a/hello/src/lib.rs b/hello/src/lib.rs index fbcd7d0..eb2d046 100644 --- a/hello/src/lib.rs +++ b/hello/src/lib.rs @@ -2,7 +2,7 @@ use std::thread; pub struct ThreadPool { - threads: Vec>, + workers: Vec, } impl ThreadPool { @@ -19,10 +19,10 @@ impl ThreadPool { let mut threads = Vec::with_capacity(size); for _ in 0..size { - // 创建出一些线程并将他们存储在那个矢量中 + workers.push(Worker::new(id)); } - ThreadPool { threads } + ThreadPool { workers } } pub fn execute(&self, f: F) @@ -31,3 +31,16 @@ impl ThreadPool { { } } + +struct Worker { + id: usize, + thread: thread::JoinHandle<()>, +} + +impl Worker { + fn new(id: usize) -> Worker { + let thread = thread::spawn(|| {}); + + Worker { id, thread } + } +}