12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- use std::thread;
-
- pub struct ThreadPool{
- workers: Vec<Worker>,
- }
-
- impl ThreadPool {
- pub fn new(size: usize) -> ThreadPool {
- assert!(size > 0);
-
- let mut workers = Vec::with_capacity(size);
-
- for id in 0..size {
- workers.push(Worker::new(id));
- }
-
- ThreadPool {
- workers
- }
-
- }
-
- pub fn execute<F>(&self, f: F)
- where F: FnOnce() + Send + 'static {
-
- }
-
- // pub fn spawn<F, T>(f: F) -> JoinHandle<T>
- // where
- // F: FnOnce() -> T + Send + 'static,
- // T: Send + 'static
- // {
-
- // }
-
- }
-
- struct Worker {
- id: usize,
- thread: thread::JoinHandle<()>,
- }
-
- impl Worker {
- fn new(id: usize) -> Worker {
- let thread = thread::spawn(|| {});
-
- Worker {
- id,
- thread,
- }
- }
- }
|