Commit b223c694 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Change to a bounded channel

parent 9d52c666
[package]
name = "hashtoc"
version = "0.1.4"
version = "0.1.5"
authors = ["Anders Blomdell <anders.blomdell@control.lth.se>"]
build = "build.rs"
links = "libhash.a,libssl"
......
......@@ -29,7 +29,7 @@ use std::ffi::OsStr;
use std::os::unix::ffi::OsStrExt;
use std::fs::{Metadata};
use std::path::{Path, PathBuf};
use std::sync::mpsc::{channel, Receiver, Sender};
use std::sync::mpsc::{sync_channel, Receiver, SyncSender};
use std::thread;
use std::fmt;
use std::process::exit;
......@@ -178,7 +178,7 @@ struct WorkerPool<T> {
pool: ThreadPool,
pending: usize,
rx: Receiver<T>,
tx: Sender<T>
tx: SyncSender<T>
}
/*trait ExecuteIf {
......@@ -192,7 +192,7 @@ impl ExecuteIf for WorkerPool {
*/
impl<T> WorkerPool<T> {
fn new(jobs: usize) -> WorkerPool<T> {
let (tx, rx) = channel::<T>();
let (tx, rx) = sync_channel::<T>(jobs * 2);
WorkerPool {
pool: ThreadPool::new(jobs),
pending: 0,
......@@ -626,9 +626,9 @@ fn main() -> std::io::Result<()> {
.index(1))
.get_matches();
let (worker, tx) = {
let (tx, rx) = channel();
let jobs = option_t_or_exit!(matches, "jobs", usize).unwrap_or(1);
let (tx, rx) = sync_channel(jobs * 2);
let args = matches.clone();
let worker = thread::spawn(move|| { dispatcher(args, rx); });
(worker, tx)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment