High-Level Parallelism – Threadpools, Parallel Iterators and Processes

In previous chapters, we introduced the basic mechanisms of concurrency in the Rust—programming language. In Chapter 4, Sync and Send – the Foundation of Rust Concurrency, we discussed the interplay of the type system of Rust with concurrent programs, how Rust ensures memory safety in this most difficult of circumstances. In Chapter 5, Locks  Mutex, Condvar, Barriers and RWLock, we discussed the higher, so-called coarse, synchronization mechanisms available to us, common among many languages. In Chapter 6, Atomics – the Primitives of Synchronization, and Chapter 7, Atomics  Safely Reclaiming Memory, we discussed the finer synchronization primitives available on modern machines, exposed through Rust's concurrent memory model. This has all been well and good but, though we've done deep-dives into select libraries or data structures, we have yet to see the consequences of all of these tools on the structure of programs, or how you might choose to split up your workloads across CPUs depending on need.

In this chapter, we will explore higher-level techniques for exploiting concurrent machines without dipping into manual locking or atomic synchronization. We'll examine thread pooling, a technique common in other programming languages, data parallelism with the rayon library, and demonstrate multiprocessing in the context of a genetic programming project that will carry us into the next chapter, as well.

By the end of this chapter, we will have:

  • Explored the implementation of thread pool
  • Understood how thread pooling relates to the operation of rayon
  • Explored rayon's internal mechanism in-depth
  • Demonstrated the use of rayon in a non-trivial exercise
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.246.245