Sfoglia il codice sorgente

Change to workers

master
Noelle 4 anni fa
parent
commit
3ae773ae0b
1 ha cambiato i file con 41 aggiunte e 2 eliminazioni
  1. 41
    2
      src/lib.rs

+ 41
- 2
src/lib.rs Vedi File

pub struct ThreadPool;
use std::thread;

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


impl ThreadPool { impl ThreadPool {
pub fn new(size: usize) -> ThreadPool { pub fn new(size: usize) -> ThreadPool {
assert!(size > 0); 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) pub fn execute<F>(&self, f: F)
where F: FnOnce() + Send + 'static { 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…
Annulla
Salva