4 ms·
The threadpool crate is great, but there is a lot more going on with it than this library. Incidentally, we build a small threadpool in the final chapter of th
by steveklabnik 7y ago
The threadpool crate is great, but there is a lot more going on with it than this library.
Incidentally, we build a small threadpool in the final chapter of the Rust book. Most of the implementation is described here, https://doc.rust-lang.org/nightly/book/ch20-02-multithreaded.html https://doc.rust-lang.org/nightly/book/ch20-02-multithreaded... with a bit in the following section. Here's all the code together: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=0a2248e959e8f1d499f4fe4ed1c86f63 https://play.rust-lang.org/?version=stable&mode=debug&editio...
One difference between this pool and the library in the OP is that the OP's pool returns handles that you can use to get jobs out of the pool, whereas this one does not. You can add that functionality on top of this pool by capturing a channel, but it's nice that they have it built in. It's not needed for the example I wrote the pool of, which is handling HTTP connections, so I didn't put it in there.
Looking at this example makes me wonder if I can simplify this even further; it’d be nice to remove that ref count. Not for performance reasons, just to make there be even less code.