David Gries Advisory Board F
Total Page:16
File Type:pdf, Size:1020Kb
Texts and Monographs in Computer Science Editor David Gries Advisory Board F. L. Bauer J. J. Horning R.Reddy D. C. Tsichritzis W. M. Waite Fairness Nissim Francez With 147 Illustrations Springer-Verlag New York Berlin Heidelberg Tokyo Nissim Francez Department of Computer Science Technion-Israel Institute of Technology Haifa 32000 Israel Series Editor David Gries Department of Computer Science Cornell University Ithaca, NY 14853 U.S.A. ACM Classifications: D.1.3, D.2.4, D.3.1, D.4.1, F.1.2, F.3.l, F.3.3 Library of Congress Cataloging in Publication Data Francez, Nissim. Fairness. (Texts and monographs in computer science) Bibliography: p. Includes index. I. Electronic digital computers-Programming. 2. Programming languages (Electronic computers) Semantics. 3. Parallel processing (Electronic computers) I. Title. II. Series. QA76.6.F7226 1986 005.4'3 86-6565 © 1986 by Springer-Verlag New York Inc. Softcover reprint of the hardcover 1st edition 1986 All rights reserved. No part of this book may be translated or reproduced in any form without written permission from Springer-Verlag, 175 Fifth Avenue, New York, New York 10010, U.SA Media conversion by House of Equations Inc., Newton, New Jersey. Printed and bound by R.R. Donnelley & Sons, Harrisonburg, Virginia. Printed in the United States of America. 987 6 5 432 I ISBN-13:978-1-4612-9347-7 e-ISBN-13: 978-1-4612-4886-6 DOl: 10.1007/978-1-4612-4886-6 To Tikva, the fairest of them all Two roads diverged in a yellow wood, And sorry I could not travel both And be one traveler, long I stood And looked down one as far as I could To where it bent in the undergrowth; Then took the other, as just as fair, And having perhaps the better claim, Because it was grassy and wanted wear; Though as for that the passing there Had worn them really about the same, And both that morning equally lay In leaves no step had trodden black. Oh, I kept the first for another day! Yet knowing how way leads on to way, I doubted if I should ever come back. I shall be telling this with a sigh Somewhere ages and ages hence: Two roads diverged in a wood, and 1- ][ took the one less traveled by, And that has made all the difference. -Robert Frost, The Road Not Taken Preface The main purpose of this book is to bring together much of the research conducted in recent years in a subject I find both fascinating and impor tant, namely fairness. Much of the reported research is still in the form of technical reports, theses and conference papers, and only a small part has already appeared in the formal scientific journal literature. Fairness is one of those concepts that can intuitively be explained very brieft.y, but bear a lot of consequences, both in theory and the practicality of programming languages. Scientists have traditionally been attracted to studying such concepts. However, a rigorous study of the concept needs a lot of detailed development, evoking much machinery of both mathemat ics and computer science. I am fully aware of the fact that this field of research still lacks matu rity, as does the whole subject of theoretical studies of concurrency and nondeterminism. One symptom of this lack of maturity is the proliferation of models used by the research community to discuss these issues, a variety lacking the invariance property present, for example, in universal formalisms for sequential computing. I was personally involved in much of the research reported in the book, in the form of original contribution, refereeing, discussions with others active in the subject, and have closely followed the developments. I did my best to present as uniformly as I could both my (and my colleagues') results as well as results by others. At the current state of the art I have found this to be a very difficult task. Thus, in many cases I drew heavily on the original presentations, often copying much of their text and mak ing changes appropriate to the framework. The book is mainly intended for the graduate student and active researcher level. Much of it needs only the usual computer science under graduate background in program verification and some mathematical and viii Preface logical maturity. Parts of the needed background are reviewed briefly. Chapters 6, 7, and (part of) 8 need more knowledge in mathematical logic, set theory, and some knowledge of algebra and topology. In deciding how to organize the book, I made two major decisions: (I) Choose (fair) termination as the basic property under investigation. Termination is a good representative of all other properties that depend on fairness. (2) Choose proofobligations (and rules) as the main tool used in the inves tigation. The organization of the book is as follows: - Chapter 0 gives a very general background and introduces the pro gramming language used in most of the discussion in the book. - Chapter I reviews the standard method of proving termination of pro grams. - Chapter 2 pn$ents one proof method for fair termination (the helpful directions) in two variants, which are interrelated. - Chapter 3 presents the other prevailing method for fair termination proofs (explicit schedulers) and also deals with random assignments. Chapters 2 and 3 are the core of the book. Later chapters present extensions in various directions. - Chapter 4 prc!serves the same programming language and presents a variety of extensions and generalizations of the fairness notions involved. - Chapter 5 pn$erves the simple fairness notions and extends the pro gramming language constructs to cover various aspects of concurrency and communication. - Chapter 6 presents a formalized logical presentation of the issues dealt with semantic,ally in Chapter 2. - Chapter 7 presents yet another logical framework with a different paradigm. - Chapter 8 uses a functional approach and is concerned with rules gen erating fairness while all previous chapters were concerned with the consequences of assuming it. The chapter also briefly discusses one other fairness-like concept-the finite delay. I am definitely sure that we are far away from having said the last word on the faiffil~ss issue. I hope that this book will present the scientific community with a tool for relating to past research and a stimulus of car rying on further n$earch. Preface ix Acknowledgments I started to write the book while on sabbatical at the IBM-T.J. Watson Research Laboratories in Yorktown Heights. I wish to thank the mathematics department there for providing the time and means for embarking on such a project. I would like to thank David Gries for encouraging me in this project, suggesting to publish the book in the series edited by him, and for criti cally reading some chapters of the early versions. With the following colleagues I had many stimulating discussions and arguments both about the subject and about the book: K.R. Apt., R.J. Back, E.M. Clarke, A Emerson, R. Gerth, O. Grumberg, D. Harel, S. Katz, D. Kozen, R. Kurki-Suonio, D. Lehmann, J.A Makowsky, R. Milner, E.-R. Olderog, D. Park, A Pnueli, S. Porat, J. Siffakis, C. Ster ling, W. P. de Roever, and AP. Sistla. I especially thank Frank Stomp for critically reading the whole manuscript and having many useful suggestions. At Yorktown Heights, Nancy A Perry and Barbara White were more than helpful in typing a preliminary version. The artwork was also done at Yorktown Heights, by the art department. Raya Anavi, at the Com puter Science Department, Technion, did a fine job, very devoutedly, in typing and formatting the final version. I also thank Anat Ha-Levi for the frontispiece drawing. While at the Technion, the work on the book was partially supported by the Fund for the Promotion of Research in the Technion. Table of Contents CHAPTER 0 Introduction 0.1 Motivation and Background I 0.2 A Taxonomy of Faimess Concepts 4 OJ The Language of Guarded Commands (GC) 7 003.1 A partial-correctness proof system for GC 13 CHAPTER 1 Termination and Well·Foundedness IS 1.0 Overview IS 1.1 Termination Proofs for Deterministic Programs 17 1.2 Termination Proofs for Nondeterministic Programs 20 CHAPTER 2 The Method of Helpful Directions 24 2.0 Introduction to Fair Termination 24 2.1 Ordinal Directed Choice of Helpful Directions 26 2.1.1 A proof rule for unconditionally-fair termination 26 2.1.2 Weakly-fair termination 36 2.103 Strongly-fair termination 39 2.2 State Directed Choice of Helpful Directions 45 2.2.1 Unconditionally-fair termination 45 2.2.2 Weakly-fair and strongly-fair termination 48 203 Inter-reducibility of the Two Methods 51 2.4 Relativized Fair Termination 53 CHAPTER 3 The Method of Explicit Scheduler 58 3.0 Overview 58 3.0.1 Random assignments 58 xii Table of Contents 3.1 Unconditionally-Fair Termination 59 3.2 Weak and Strong Fairness: n Guards 73 3.2.1 Examples ~or strong fairness 78 3.2.2 Alternative transformations 79 3.3 All-Levels Faimess 80 3.4 Comparing Explicit Scheduler with Helpful Directions 86 3.5 More on Fairnc:ss and Random Assignments 88 CHAPTER 4 Extension and Ge'nerallzatlons of Fairness 94 4.0 Overview 94 4.1 Equifairness 95 4.1.1 Unconditional equifairness 96 4.1.2 Strong equifairness 103 4.2 Generalized Fairness 112 4.3 Extreme Fairness 118 4.3.0 Overview 118 4.3.1 Proof rules for extremely-fair termination 121 4.4 An Analysis of IPredicate-Reachability Fairness 126 CHAPTERS Fair Termination c)f Concurrent Processes 132 5.1 Overview 132 5.2 Fairness and Communicating Processes 133 5.2.1 The CSP sublanguage for communicating processes 133 5.2.2 Serialized sl~mantics and overlapping semantics 137 5.2.3 Relativized fair termination in the