瀏覽代碼

Change to workers

master
Noelle 4 年之前
父節點
當前提交
3ae773ae0b
共有 1 個檔案被更改,包括 41 行新增2 行删除
  1. 41
    2
      src/lib.rs

+ 41
- 2
src/lib.rs 查看文件

@@ -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…
取消
儲存