Yes, let me elaborate on this point. Our goal with the current design is that there should be exactly one global thread-pool for all users of Rayon, regardless of how many different versions they use simultaneously. This is for two reasons:
- Throughput: a single thread-pool is better, all things being equal, since you don’t oversubscribe the CPU. (It can, however, lead to observed latency, since you might wind up waiting for work that some other library is doing.)
- Deadlock potential: if you combine multiple thread-pools, there is some potential for dead-lock, since you can wind up with one thread-pool blocked on another
- This is similar to doing blocking I/O, effectively.
- It’s a bit tricky to do, you have to effectively have thread-pool A spawn some work into thread-pool B and block on the result (e.g., using
join()), and then have thread-pool B call back into thread-pool A and do the same. But it could arise if you have library A and B, both using rayon, but with different global threadpools, and they have callbacks that call into one another.
Now, even with the current design, there are no strict guarantees. In fact, I think it’s safe to say that having a library use Rayon and invoke some callback from the Rayon thread is slightly risky, at least if you haven’t informed users about your intentions (e.g., that callback could do blocking I/O, you don’t know). Since one can create multiple thread-pools explicitly, you could induce the same sort of deadlocks that way. But overall it was deemed better to push that concern onto those few users that create their own global thread-pools. Ergonomically, Rayon definitely tries to steer you to the global thread-pool, which means you get both improved throughput and a reduced risk of deadlock.
Yes, it will continue to do so, and no, there is no particular reason not to depend on
rayon_core directly. The idea is that there is only one major version of
rayon_core for all time: i.e., we stay in the
1.x series indefinitely. therefore, cargo’s resolution algorithms will always give you one version of rayon-core across your project, and hence one global pool.