parent
bbf889e72e
commit
e4211e27bf
1 changed files with 10 additions and 8 deletions
18
src/main.rs
18
src/main.rs
|
|
@ -6,23 +6,25 @@ use std::{sync, thread};
|
|||
|
||||
static GET: &'static [u8] = b"GET / HTTP/1.1\r\n";
|
||||
|
||||
pub struct ThreadPool {
|
||||
workers: Vec<Worker>,
|
||||
sender: mpsc::Sender<Job>,
|
||||
}
|
||||
|
||||
struct Worker {
|
||||
id: usize,
|
||||
thread: thread::JoinHandle<()>,
|
||||
}
|
||||
|
||||
impl Worker {
|
||||
fn new(id: usize) -> Worker {
|
||||
let thread = thread::spawn(|| {});
|
||||
fn new(id: usize, receiver: mpsc::Receiver<Job>) -> Worker {
|
||||
let thread = thread::spawn(|| {
|
||||
receiver;
|
||||
});
|
||||
Worker { id, thread }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ThreadPool {
|
||||
workers: Vec<Worker>,
|
||||
sender: mpsc::Sender<Job>,
|
||||
}
|
||||
|
||||
impl ThreadPool {
|
||||
/// Create a new ThreadPool
|
||||
///
|
||||
|
|
@ -34,7 +36,7 @@ impl ThreadPool {
|
|||
let mut workers = Vec::with_capacity(size);
|
||||
let (sender, receiver) = mpsc::channel();
|
||||
for id in 0..size {
|
||||
workers.push(Worker::new(id))
|
||||
workers.push(Worker::new(id, receiver))
|
||||
}
|
||||
Self { workers, sender }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue