Concepts of Programming Languages

(Sean Pound) #1

576 Chapter 13 Concurrency


T


his chapter begins with introductions to the various kinds of concurrency at
the subprogram, or unit level, and at the statement level. Included is a brief
description of the most common kinds of multiprocessor computer architec-
tures. Next, a lengthy discussion on unit-level concurrency is presented. This begins
with a description of the fundamental concepts that must be understood before
discussing the problems and challenges of language support for unit-level concur-
rency, specifically competition and cooperation synchronization. Next, the design
issues for providing language support for concurrency are described. Following this
is a detailed discussion of three major approaches to language support for concur-
rency: semaphores, monitors, and message passing. A pseudocode example program
is used to demonstrate how semaphores can be used. Ada and Java are used to
illustrate monitors; for message passing, Ada is used. The Ada features that support
concurrency are described in some detail. Although tasks are the focus, protected
objects (which are effectively monitors) are also discussed. Support for unit-level
concurrency using threads in Java and C# is then discussed, including approaches
to synchronization. This is followed by brief overviews of support for concurrency in
several functional programming languages. The last section of the chapter is a brief
discussion of statement-level concurrency, including an introduction to part of the
language support provided for it in High-Performance Fortran.

13.1 Introduction


Concurrency in software execution can occur at four different levels: instruction
level (executing two or more machine instructions simultaneously), statement
level (executing two or more high-level language statements simultaneously),
unit level (executing two or more subprogram units simultaneously), and pro-
gram level (executing two or more programs simultaneously). Because no lan-
guage design issues are involved with them, instruction-level and program-level
concurrency are not discussed in this chapter. Concurrency at both the sub-
program and the statement levels is discussed, with most of the focus on the
subprogram level.
At first glance, concurrency may appear to be a simple concept, but it
presents significant challenges to the programmer, the programming language
designer, and the operating system designer (because much of the support for
concurrency is provided by the operating system).
Concurrent control mechanisms increase programming flexibility. They
were originally invented to be used for particular problems faced in operating
systems, but they are required for a variety of other programming applica-
tions. One of the most commonly used programs is now Web browsers, whose
design is based heavily on concurrency. Browsers must perform many differ-
ent functions at the same time, among them sending and receiving data from
Web servers, rendering text and images on the screen, and reacting to user
actions with the mouse and the keyboard. Some contemporary browsers, for
example Internet Explorer 9, use the extra core processors that are part of many
contemporary personal computers to perform some of their processing, for
Free download pdf