
<!-- Thank you for your Pull Request. Please provide a description above and review the requirements below. Bug fixes and new features should include tests. Contributors guide: https://github.com/tokio-rs/tokio/blob/master/CONTRIBUTING.md --> ## Motivation Now that each worker thread drives its own reactor, reactors have to be driven until the threadpool shuts down. We mustn't use the `keep_alive` setting to shut down a worker thread if it doesn't receive an event from the reactor for a certain duration of time. <!-- Explain the context and why you're making that change. What is the problem you're trying to solve? In some cases there is not a problem and this can be thought of as being the motivation for your change. --> ## Solution Just ignore the `keep_alive` setting when parking in `Worker::sleep`. <!-- Summarize the solution and provide any necessary context needed to understand the code change. -->
Tokio Thread Pool
A library for scheduling execution of futures concurrently across a pool of threads.
Why not Rayon?
Rayon is designed to handle parallelizing single computations by breaking them into smaller chunks. The scheduling for each individual chunk doesn't matter as long as the root computation completes in a timely fashion. In other words, Rayon does not provide any guarantees of fairness with regards to how each task gets scheduled.
On the other hand, tokio-threadpool
is a general purpose scheduler and
attempts to schedule each task fairly. This is the ideal behavior when
scheduling a set of unrelated tasks.
Why not futures-cpupool?
It's 10x slower.
Examples
extern crate tokio_threadpool;
extern crate futures;
use tokio_threadpool::ThreadPool;
use futures::{Future, lazy};
use futures::sync::oneshot;
pub fn main() {
let pool = ThreadPool::new();
let (tx, rx) = oneshot::channel();
pool.spawn(lazy(|| {
println!("Running on the pool");
tx.send("complete").map_err(|e| println!("send error, {}", e))
}));
println!("Result: {:?}", rx.wait());
pool.shutdown().wait().unwrap();
}
License
This project is licensed under the MIT license.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Tokio by you, shall be licensed as MIT, without any additional terms or conditions.