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";
|
static GET: &'static [u8] = b"GET / HTTP/1.1\r\n";
|
||||||
|
|
||||||
pub struct ThreadPool {
|
|
||||||
workers: Vec<Worker>,
|
|
||||||
sender: mpsc::Sender<Job>,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Worker {
|
struct Worker {
|
||||||
id: usize,
|
id: usize,
|
||||||
thread: thread::JoinHandle<()>,
|
thread: thread::JoinHandle<()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Worker {
|
impl Worker {
|
||||||
fn new(id: usize) -> Worker {
|
fn new(id: usize, receiver: mpsc::Receiver<Job>) -> Worker {
|
||||||
let thread = thread::spawn(|| {});
|
let thread = thread::spawn(|| {
|
||||||
|
receiver;
|
||||||
|
});
|
||||||
Worker { id, thread }
|
Worker { id, thread }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct ThreadPool {
|
||||||
|
workers: Vec<Worker>,
|
||||||
|
sender: mpsc::Sender<Job>,
|
||||||
|
}
|
||||||
|
|
||||||
impl ThreadPool {
|
impl ThreadPool {
|
||||||
/// Create a new ThreadPool
|
/// Create a new ThreadPool
|
||||||
///
|
///
|
||||||
|
|
@ -34,7 +36,7 @@ impl ThreadPool {
|
||||||
let mut workers = Vec::with_capacity(size);
|
let mut workers = Vec::with_capacity(size);
|
||||||
let (sender, receiver) = mpsc::channel();
|
let (sender, receiver) = mpsc::channel();
|
||||||
for id in 0..size {
|
for id in 0..size {
|
||||||
workers.push(Worker::new(id))
|
workers.push(Worker::new(id, receiver))
|
||||||
}
|
}
|
||||||
Self { workers, sender }
|
Self { workers, sender }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue