We’ll be examining all of Clojure’s flexible concurrency
facilities in a bit, one of which—agents—can be used to orchestrate very
efficient parallelization of workloads. However, sometimes you may find
yourself wanting to parallelize some operation with as little ceremony as
possible.
Parallelism Versus Concurrency
Lest our discussion of concurrency and parallelism lead you to think they are the same thing,
let’s disentangle the two notions.
Concurrency is the coordination of multiple,
usually interleaved threads of execution that are accessing or modifying
some shared state.
Parallelism involves state as well, but
usually in the inverse. Being an optimization technique used to
efficiently utilize all of the available resources (usually
computational, but sometimes other resources, like bandwidth) to improve
the performance of an operation, approaches to parallelization generally
aim to maximize the window of exclusive access to state (or, often,
chunks of state) so as to minimize coordination overhead. Rather than
involving interleaved threads of execution, the multiple evaluations of
a parallelized operation run simultaneously—sometimes on different CPU
cores, other times on different physical machines entirely.
You are currently reading a PREVIEW of this book.
Get instant access to over
$1 million worth of books and videos.