![](https://csdnimg.cn/release/download_crawler_static/10212150/bg13.jpg)
1.1. MOTIVATION 3
the code that each thread executes, when or how threads communicate, or how tasks are assigned
to threads. The model is a general one, capable of expressing all forms of parallel computation. It,
however, is very difficult to program correctly. In many ways, the model is at the same (low) level of
abstraction as the underlying computer’s hardware; in fact, processors directly implement many of
the constructs used to write this type of program.
1.1.2 PARALLEL PROGRAMMING ABSTRACTIONS
A key shortcoming of task parallelism is its lack of effective mechanisms for abstraction and
composition—computer science’s two fundamental tools for managing complexity. An abstraction
is a simplified view of an entity, which captures the features that are essential to understand and
manipulate it for a particular purpose. People use abstraction all the time. For example, consider an
observer “Jim” and a dog “Sally” barking from the backyard across the street. Sally is Jim’s abstraction
of the dog interrupting his writing of this book. In considering her barking, Jim need not remember
that Sally is actually a one-year-old Golden Retriever and, certainly, Jim does not think of her as a
quadruped mammal. The latter specifics are true, but not germane to Jim’s irritation at the barking.
Abstraction hides irrelevant detail and complexity, and it allows humans (and computers) to focus
on the aspects of a problem relevant to a specific task.
Composition is the ability to put together two entities to form a larger, more complex entity,
which, in turn, is abstracted into a single, composite entity. Composition and abstraction are closely
related since details of the underlying entities can be suppressed when manipulating the composite
product. Composition is also a common human activity. Consider an engineered artifact such as a car,
constructed from components such as an engine,brakes, body, etc. For most purposes, the abstraction
of a car subsumes these components and allows us to think about a car without considering the details
explored in automobile enthusiast magazines.
Modern programming languages support powerful abstraction mechanisms, as well as rich
libraries of abstractions for sequential programming. Procedures offer a way to encapsulate and
name a sequence of operations. Abstract datatypes and objects offer a way to encapsulate and name
data structures as well. Libraries, frameworks, and design patterns collect and organize reusable
abstractions that are the building blocks of software. Stepping up a level of abstraction, complex
software systems,such as operating systems,databases or middleware,provide the powerful,generally
useful abstractions, such as virtual memory,file systems, or relational databases used by most software.
These abstraction mechanisms and abstractions are fundamental to modern software development
which increasingly builds and reuses software components, rather than writing them from scratch.
Parallel programming lacks comparable abstraction mechanisms. Low-level parallel program-
ming models, such as threads and explicit synchronization, are unsuitable for constructing abstrac-
tions because explicit synchronization is not composable. A program that uses an abstraction con-
taining explicit synchronization must be aware of its details, to avoid causing races or deadlocks.
Here is an example. Consider a hashtable that supports thread-safe Insert and Remove
operations. In a sequential program, each of these operations can be an abstraction. One can fully