parent
5795b74d8e
commit
24f0ca7de1
1 changed files with 18 additions and 6 deletions
24
src/main.rs
24
src/main.rs
|
|
@ -6,7 +6,19 @@ use std::thread;
|
|||
static GET: &'static [u8] = b"GET / HTTP/1.1\r\n";
|
||||
|
||||
pub struct ThreadPool {
|
||||
threads: Vec<thread::JoinHandle<()>>,
|
||||
workers: Vec<Worker>,
|
||||
}
|
||||
|
||||
struct Worker{
|
||||
id: usize,
|
||||
thread: thread::JoinHandle<()>,
|
||||
}
|
||||
|
||||
impl Worker {
|
||||
fn new(id: usize) -> Worker {
|
||||
let thread = thread::spawn(|| {});
|
||||
Worker { id, thread }
|
||||
}
|
||||
}
|
||||
|
||||
impl ThreadPool {
|
||||
|
|
@ -17,13 +29,13 @@ impl ThreadPool {
|
|||
/// The `new` function panics if the size is zero
|
||||
pub fn new(size: usize) -> Self {
|
||||
assert!(size > 0);
|
||||
let threads = Vec::with_capacity(size);
|
||||
for _ in 0..size {
|
||||
|
||||
let mut workers = Vec::with_capacity(size);
|
||||
for id in 0..size {
|
||||
workers.push(Worker::new(id))
|
||||
}
|
||||
Self {threads}
|
||||
Self {workers}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue