From b223c694c73acaa800d8bf117bb3f024d35d3dbd Mon Sep 17 00:00:00 2001
From: Anders Blomdell <anders.blomdell@control.lth.se>
Date: Tue, 8 Jan 2019 12:54:26 +0100
Subject: [PATCH] Change to a bounded channel

---
 Cargo.toml  |  2 +-
 src/main.rs | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 5f3ec27..aa81125 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [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"
diff --git a/src/main.rs b/src/main.rs
index 7eca017..9f4b8ed 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -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)
-- 
GitLab