
Concurrent Programming Concepts Per Brinch Hansen Information California Institute of Technology, Pasadena, California 91109 This paper describes the evolution of language features for multiprogramming from event queues and semaphores to critical regions and monitors. It suggests that the choice of language concepts shouldbe guided by two simple principles : First, it should be possible to understand a concurrent program in time- independent terms by an effort proportional to its size; secondly, it should be possible to state assumptions about invariant relationships among program components and have these assumptions checked automatically. The central problems of multiprogramming are illustrated by annotated algorithms written in a well-structuredprogramming language. Key words and phrases: structured multiprogramming, programming languages, operating systems, programming errors, resource protection, compile-time checking, correctness proofs, sequential and concurrent processes, synchronizing events, semaphores, shared data, mutual exclusion, critical regions, monitors. CR categories: 4.22, 4.31, 4.32, 5.24 Somewhere there are decisions made that are programming systems. The techniques used not rational in any sense, that are subject to to implement these language concepts, which nothing more than the personal bias of the apply single-processor and decision maker. Logical methods, at best, re- both to multi- arrange the way in which personal bias is to processor systems, are described elsewhere. be introduced into a problem. Of course, this [1] "at best" is rather important. Present intuitive When a new programming technique, such methods unhappily introduce personal bias in as multiprogramming, is program- such a way that it makes problems impossible invented, to solve correctly. Our purpose must be to re- mers will initially use it in a completelyun- pattern the bias, so that it no longer interferes restricted manner to discover its potential. in this destructive way with the process of At a later stage, when experience with its design, and no longer inhibits clarity of form. practical limitations has been gained, de- Chistopher Alexander, Notes on the Synthesis a ofForm signers begin to recognize the benefits of more restrictive language notation which clarifies their own understanding of pro- 1. INTRODUCTION grams and enables compilers to detect seri- ous errors. This paper describes an attitude toward This survey describes the evolution of lan- multiprogramming—the programming tech- guage features for multiprogramming during niques used to control concurrent activities the past decade. I view this development by computers.* It tries to identify abstract mainly gradual shift from concepts that properties as a of programming languages that have a strong resemblance to assembly lan- facilitate the design of large,reliable multi- guage features toward a notation that en- * In this paper, the term multiprogramming is used courages hierarchical structuring of pro- consistently to denote all programming techniques grams. Several useful proposals are not used to control concurrent processes on single- processor aswell as multiprocessorsystems. mentioned here, and those that are included Computing Surveys, Vol. 5, No. December 1973 Science, 4, 224 Per Brinch Hansen Concurrent Programming Concepts CONTENTS are only meant to illustrate a general atti- and variables) and operations on data (rep- The following assertions will hold before tude toward the subject. resented by statements). During the execu- the execution of lines 1-8,respectively. The central problems of multiprogram- tion of the program, the operations are car- comment 1 0 out of n records processed ming are illustrated by algorithms written ried out strictly one at a time, and each (where 0 n) ; in a high-level language.I have included in- operation is completed within a finite time. comment 2 i out of n records processed formal assertions in the algorithms and out- The result of an operation can be defined by (where 0 i n) ; lined arguments of their correctness to show assertions about the relationships of data comment 3 i out of n records processed 1. Introduction 223 that multiprogramming concepts can be de- before and after its execution. (where 0 i < n) ; 2. SequentialProcesses 224 fined as concisely as sequential program- In Algorithm 1, we can make the following comment 4 i out of n records processed 3. Unrestricted Concurrency 226 ming concepts. In many ways, this survey assertions about the state of the (where 4. Structured Concurrency228 variables 0 i < n), and this = input 5. Disjoint Processes 230 can be regarded as an expanded version of before and after the execution of the input record Ri + 1 ; 6. Time-DependentErrors 231 an earlier paper [2]. We will begin with a statement in line 3: comment i out n processed 7. Timing Signals233 5 of records brief characterization of sequential pro- comment 3 i n 8. Critical Regions 236 out of records processed (where 0 i < n) , and this = updated 9. Critical Regions 241 grams. (where 0 i < n) ; record Ri + 1 ; 10. Conclusion 244 get (this, reader) comment 6 out Acknowledgements244 ; i + 1 of n records proc- Bibliography 244 comment 4 i out of n records processed essed (where 0 i < n) ; 2. SEQUENTIAL PROCESSES (where 0 i < n), and this = input comment 7 i out of n records processed record Ri 1; (where 0< i n) ; Although most programmers an + have intui- Sequential programs have two prop- comment 8 n out n processed understanding vital of records tive of what a sequential erties : (where 0 n) ; is, it may be useful to illustrate this s^ process 1) The a sequential program is Once the individual- statements are under- concept by an example.Algorithm 1 defines effect of independent of its speed execution. All stood, one can define the effect of a sequence a sequential that inputs fixed of process a that matters is that operations are of by a single pair RI, R2, ,Rn carried statements of assertions. number of records . from out one at a time with positive speed, and As an example, the body of the while sequential updates these state- one file, records, that certain relationships hold before and ment in Algorithm 1 can outputs them on another sequential file. be defined as a and after their execution. The time-independent single operation by means of the following The language notation is borrowed from behavior of sequential programs enables the assertions: are two Pascal. [3] The files declared as user to ignore details over which he has comment 3 each consist- no i out of n records processed variables, reader and printer, control (such as the schedulingpolicy (where 0 i n) of type T of the < ; ing of a sequence of records some operating system and the precise timing of process nextrecord and increment i by (declaredelsewhere) A type can . record of T operations carried out by processors pe- one; from and be appended to or removed a sequence ripherals). comment 7 i out n put of records processed by means of two standard procedures, 2) A sequentialprogram delivers the same (where 0< i n) ; and get. The current record is kept in a vari- result each time it is executed with a given The next step of simplification is to re- of type T. The variable i counts able, this, set of input data. The reproducible behavior duce the while statement to a single opera- processed; can as- the number of records it of sequential programs under any tion: 0 to n. circum- sume integer values from stances particularly comment 2 i out n records processed Algorithm 1 Sequential file updating is important for pro- of gram validation. It enables one to isolate (where 0 i n) ; var reader, printer: sequence of T; and correct program errors by systematic process the remaining n-i records; this: T; i: 0. n; testing. comment 8 n out of n records processed (where begin These properties of sequential programs 0 n) ; Finally, the (1) i:=0; are so well known that we tend to take them whole programcan be defined as a single operation: (2) while i<n do for granted. But as we shall see, these prop- (3) get (this, reader) ; erties can only be comment 1 0 out of n records processed maintained for multipro- (where 0 n) (4) update (this) ; gramming systems by a ; careful selection of process n Copyright © 1973, Association for Computing (5) put (this, printer) ; language concepts. records; Machinery, Inc. General permission to republish, (6) i l; comment 8 n out n records processed i: = + Algorithm 1 is a well-structured program of but not for profit, all or part of this material is (7) (where 0 n) ; is end that can be analyzed granted, provided that ACM's copyright notice in a step-wise manner At this point, only what the program does as given and that reference is made to this publica- (8) end as a set of nested operations. At the most a whole, is relevant, but the details of how tion, to its date of issue, and to the fact that re- The program defines a sequential process detailed level, the program printing privileges were grantedby permission of can be described it is done are irrelevant. The possibility of by constants in the Association for Computing Machinery. in terms of data (represented terms of assertions about each statement. replacing complex descriptions by partial Computing Surveys, Vol. 5, No. December 1973 Computing Surveys, Vol. 5, No. December 1973 225 Conditional 4, 4, 226 Per Brinch Hansen Concurrent Programming Concepts 227 tain functional aspects of it can be described start task do SI tions. Algorithm 2 is deliberately written in in even more economical terms. This is the an unstructured manner that makes it diffi- whole purpose of structured programming! will start the execution of statement SI as cult to understand. A well-structured algo- It is also essential to use hierarchical a new process.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages12 Page
-
File Size-