title: rust futures-cpupool: inconsistent behavior explanations
body: <p>I'm experiencing weird behavior with <a href="https://docs.rs/futures-cpupool/0.1.2/futures_cpupool/" rel="nofollow noreferrer">cpu pools</a>:</p>
  
  <pre><code>#[macro_use]
  extern crate lazy_static;
  extern crate tokio_core;
  extern crate futures;
  extern crate futures_cpupool;
  
  use std::time::Duration;
  
  use futures_cpupool::{CpuPool, Builder, CpuFuture};
  use futures::Stream;
  use futures::{Future, future, lazy};
  use futures::sync::mpsc;
  use futures::Sink;
  
  lazy_static! {
      static ref CPU_POOL: CpuPool = {
          Builder::new()
          .pool_size(10)
          .after_start(|| {
              println!("Pool started one thread");
          })
          .before_stop(|| {
              println!("Pool stopped one thread");
          })
          .create()
      };
      }
  
  struct Producer {}
  
  impl Producer {
      fn search_names(&amp;self) -&gt; Box&lt;Stream&lt;Item = String, Error = String&gt; + Send&gt; {
          let (mut tx, rx) = mpsc::channel::&lt;Result&lt;String, String&gt;&gt;(1);
  
          println!("Creating producer thread...");
          let producer_cpu: CpuFuture&lt;(), ()&gt; = CPU_POOL.spawn(lazy(move || {
                  println!(" -- Begin to produce names");
                  for i in 0..10 {
                      match tx.send(Ok("name".to_string())).wait() {
                          Ok(t) =&gt; {
                              println!(" -- sent the name");
                              tx = t
                          }
                          Err(err) =&gt; {
                              println!(" -- Error occured sending name! {:?}", err);
                              break;
                          }
                      }
                      std::thread::sleep(Duration::from_secs(1));
                  }
                  future::ok::&lt;(), ()&gt;(())
              })
              .then(|result| {
                  match result {
                      Ok(data) =&gt; println!("Producer finished with data: {:?}", data),
                      Err(err) =&gt; println!("Producer finished with error: {:?}", err),
                  }
                  future::ok::&lt;(), ()&gt;(())
              }));
  
          rx.then(|r| r.unwrap()).boxed()
      }
  }
  
  fn main() {
      let producer = Producer {};
  
      let names = CPU_POOL.spawn(producer.search_names()
          .map(|name| {
              println!("name = {:?}", name);
              name
          })
          .collect()
          .then(|result| {
              match result {
                  Ok(data) =&gt; println!("Finished to read producer {:?}", data),
                  Err(err) =&gt; println!("Error reading stream of producer! {:?}", err),
              }
              future::ok::&lt;(), ()&gt;(())
          }));
  
      names.wait();
  }
  </code></pre>
  
  <p>Here is the corresponding Cargo.toml</p>
  
  <pre><code>[package]
  name = "example"
  version = "0.1.0"
  
  [dependencies]
  lazy_static = "^0.1.*"
  
  tokio-core = "^0.1"
  futures = "^0.1"
  futures-cpupool = "^0.1"
  </code></pre>
  
  <p>I'm running on Rust nightly (<code>1.16.0-nightly (df8debf6d 2017-01-25)</code>)</p>
  
  <p>I would expect this program to generate the 10 <code>String</code>s, output it via <code>println</code> and exit. However, most of the time, the program doesn't generate the <code>String</code>s and exits normally, other times the <code>String</code>s are correctly generated.</p>
  
  <p>Here is the output of the first case:</p>
  
  <pre class="lang-none prettyprint-override"><code>Creating producer thread...
  Pool started one thread
  Finished to read producer []
  Pool started one thread
  Pool started one thread
  Pool started one thread
  Pool started one thread
  </code></pre>
  
  <p>And the output when <code>String</code>s get generated</p>
  
  <pre class="lang-none prettyprint-override"><code>Pool started one thread
  Pool started one thread
  Pool started one thread
  Pool started one thread
  Creating producer thread...
   -- Begin to produce names
   -- sent the name
  name = "name"
  Pool started one thread
   -- sent the name
  name = "name"
  Producer finished with data: ()
  Finished to read producer ["name", "name"]
  </code></pre>
  
  <p>I got the feeling that, for the first case, the producer thread doesn't get scheduled on the thread pool for whatever reason. I must be missing something but I don't know what.</p>