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