Skip to content

Commit

Permalink
Created Channels to communicate between threads
Browse files Browse the repository at this point in the history
  • Loading branch information
dhanushrajgp committed Jul 13, 2024
1 parent 8072e4d commit 662b32e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::thread;
use std::{sync::mpsc, thread};

pub struct ThreadPool {
workers: Vec<Worker>,
sender: mpsc::Sender<Job>,
}

impl ThreadPool {
Expand All @@ -14,14 +15,15 @@ impl ThreadPool {
/// The `new` function will panic if the size is zero.
pub fn new(size: usize) -> ThreadPool {
assert!(size > 0);
let (sender, reciever) = mpsc::channel();

let mut workers = Vec::with_capacity(size);

for id in 0..size {
workers.push(Worker::new(id))
}

ThreadPool { workers }
ThreadPool { workers, sender }
}

pub fn execute<F>(&self, f: F)
Expand All @@ -31,6 +33,7 @@ impl ThreadPool {
}
}

struct Job;
struct Worker {
id: usize,
thread: thread::JoinHandle<()>,
Expand Down

0 comments on commit 662b32e

Please sign in to comment.