Browse Source

Change to workers

master
Noelle 4 years ago
parent
commit
3ae773ae0b
1 changed files with 41 additions and 2 deletions
  1. 41
    2
      src/lib.rs

+ 41
- 2
src/lib.rs View File

@@ -1,13 +1,52 @@
pub struct ThreadPool;
use std::thread;

pub struct ThreadPool{
workers: Vec<Worker>,
}

impl ThreadPool {
pub fn new(size: usize) -> ThreadPool {
assert!(size > 0);
ThreadPool

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,
}
}
}

Loading…
Cancel
Save