This page intentionally left blank BUILDING PARALLEL, EMBEDDED, AND REAL-TIME APPLICATIONS WITH ADA Thearrivalandpopularityofmulti-coreprocessorshavesparkedarenewedinterest in the development of parallel programs. Similarly, the availability of low-cost microprocessorsandsensorshasgeneratedagreatinterestinembeddedreal-time programs.Thisbookprovidesstudentsandprogrammerswhosebackgroundsarein traditionalsequentialprogrammingwiththeopportunitytoexpandtheircapabilities intoparallel,embedded,real-time,anddistributedcomputing.Italsoaddressesthe theoretical foundation of real-time schedulinganalysis, focusing on theory that is usefulforactualapplications. Written by award-winning educators at a level suitable for undergraduates and beginninggraduatestudents,thisbookisthefirsttrulyentry-leveltextbookinthe subject.Completeexamplesallowreaderstounderstandthecontextinwhichanew conceptisused,andenablethemtobuildandruntheexamples,makechanges,and observetheresults. john w. mccormick is Professor of Computer Science at the University of NorthernIowa. frank singhoff is Professor of Computer Science at Universite´ de BretagneOccidentale(UniversityofBrest). je´roˆme hugues is Associate Professor in the Department of Mathematics, Computer Science, and Control at the Institute for Space and Aeronautics Engi- neering(ISAE),Toulouse. BUILDING PARALLEL, EMBEDDED, AND REAL-TIME APPLICATIONS WITH ADA JOHN W. MCCORMICK UniversityofNorthernIowa FRANK SINGHOFF Universite´deBretagneOccidentale JE´ ROˆ ME HUGUES InstituteforSpaceandAeronautics Engineering(ISAE),Toulouse cambridge university press Cambridge,NewYork,Melbourne,Madrid,CapeTown, Singapore,Sa˜oPaulo,Delhi,Tokyo,MexicoCity CambridgeUniversityPress TheEdinburghBuilding,CambridgeCB28RU,UK PublishedintheUnitedStatesofAmericabyCambridgeUniversityPress,NewYork www.cambridge.org Informationonthistitle:www.cambridge.org/9780521197168 (cid:1)C J.W.McCormick,F.Singhoff,andJ.Hugues2011 Thispublicationisincopyright.Subjecttostatutoryexception andtotheprovisionsofrelevantcollectivelicensingagreements, noreproductionofanypartmaytakeplacewithoutthewritten permissionofCambridgeUniversityPress. Firstpublished2011 PrintedintheUnitedKingdomattheUniversityPress,Cambridge AcatalogrecordforthispublicationisavailablefromtheBritishLibrary LibraryofCongressCataloginginPublicationdata McCormick,JohnW.,1948– Buildingparallel,embedded,andreal-timeapplicationswithAda/JohnW.McCormick, FrankSinghoff,JeromeHugues. p. cm. Includesbibliographicalreferencesandindex. ISBN978-0-521-19716-8(hardback) 1.Ada(Computerprogramlanguage) 2.Parallelprogramming(Computerscience) 3.Embeddedcomputersystems–Programming. 4.Real-timedataprocessing. 5.Multiprocessors–Programming. I.Singhoff,Frank. II.Hugues,Jerome. III.Title. QA76.73.A35M375 2011 004(cid:2).35–dc22 2010053214 ISBN978-0-521-19716-8Hardback CambridgeUniversityPresshasnoresponsibilityforthepersistenceor accuracyofURLsforexternalorthird-partyinternetwebsitesreferredto inthispublication,anddoesnotguaranteethatanycontentonsuch websitesis,orwillremain,accurateorappropriate. ThephotographonthecovershowsastronautStephenK.RobinsonstandingontheendoftheInternationalSpace Station’sroboticmanipulatorsystem,Canadarm2.Thisarm,builtbyMacDonald,Dettwiler,andAssociatesLtd fortheCanadianSpaceAgency,is17.6mlongwhenfullyextended.Ithassevenmotorizedjoints,eachacomplex embeddedreal-timesystem.Givenitscrucialroleonthespacestation,thereliabilityofCanadarm2mustbe impeccable.Thesoftwareforthesejointsandfortheworkstationthattheastronautsusetocontrolthemiswritten inAda.Thisbookprovidesanintroductiontotheconceptsofconcurrentprogramming,embeddedsystems,and real-timeconstraintsnecessaryforunderstandinganddevelopingthesoftwareforsuchsystems. Contents List of illustrations page viii List of tables x Foreword xi Preface xiii 1 Introduction and overview 1 1.1 Parallel programming 2 1.2 Distributed programming 11 1.3 Real-time systems 12 Summary 19 Exercises 20 2 Sequential programming with Ada 23 2.1 Control structures 26 2.2 Subprograms 30 2.3 The Ada type model 35 2.4 Blocks and exceptions 62 2.5 Programming in the large 65 2.6 Object-oriented programming 76 2.7 Low-level programming 82 Summary 102 Exercises 103 3 Task basics 107 3.1 Defining tasks 107 3.2 The task life cycle 109 3.3 Task hierarchies 113 3.4 Exceptions 117 3.5 The implementation of Ada tasking 119 3.6 Other task features 119 vi Contents Summary 121 Exercises 122 4 Communication and synchronization based on shared objects 126 4.1 Mutual exclusion 126 4.2 The protected object 130 4.3 Synchronization 134 4.4 The protected entry 135 4.5 Restrictions 140 4.6 Entry queues 141 4.7 Some useful concurrent patterns 143 4.8 Requeue and private operations 149 4.9 Pragmas Atomic and Volatile 153 4.10 Interrupts 155 Summary 161 Exercises 162 5 Communication and synchronization based on direct interaction 166 5.1 The rendezvous 166 5.2 The selective accept statement 171 5.3 Entry call options 180 5.4 State machines 181 Summary 191 Exercises 192 6 Distributed systems with Ada 195 6.1 What are distributed systems? 195 6.2 Middleware, architectures, and concepts 200 6.3 DSA, the Distributed Systems Annex 202 6.4 PolyORB: compilation chain and run-time for the DSA 212 6.5 Advanced DSA concepts 215 6.6 CORBA, the Common Object Request Broker Architecture 221 6.7 Advanced CORBA concepts 236 6.8 CORBA versus the DSA 247 Summary 248 Exercises 250 7 Real-time systems and scheduling concepts 251 7.1 Task characteristics 253 7.2 Real-time schedulers 257 Contents vii 7.3 Dependent tasks 278 Summary 285 Exercises 286 8 Real-time programming with Ada 294 8.1 Expressing time 295 8.2 Implementing periodic tasks 298 8.3 Ada implementation of the car application 303 8.4 Handling shared resources 305 8.5 The Ada scheduling model 308 8.6 Ravenscar 312 8.7 POSIX 1003.1b and its Ada binding 314 8.8 POSIX implementation of the car application 324 8.9 Ada tasks versus POSIX processes 328 Summary 329 Exercises 330 9 Tools for building and verifying real-time applications 333 9.1 Ada run-times to implement real-time applications 334 9.2 Some variants of the GNAT run-time 339 9.3 Validating scheduling of a system 347 Summary 355 Exercises 356 References 359 Index 365 Illustrations 1.1 An example of an embedded system 16 2.1 The Ada type hierarchy 37 2.2 Distribution of model numbers 41 2.3 Access variables 58 2.4 A linked list implementation of a stack of characters 60 2.5 Class diagram for commercial ovens 78 2.6 Association between register bits and enunciation lights 84 2.7 Memory mapped input/output 87 2.8 Port mapped input/output 89 2.9 Example digital to analog converter 90 3.1 The basic states of a task 110 3.2 The substates of executable 112 3.3 Parent tasks are suspended during the activation of a child task 115 4.1 The read/write lock 133 4.2 The read lock 134 4.3 Entry queues for the protected bounded buffer 142 4.4 Tasks in the entry queues have precedence over those delayed behind the lock 143 5.1 Statement sequencing in rendezvous 167 5.2 State machine diagram notation 182 5.3 State diagram for car headlights 183 5.4 State diagram for a large induction motor 188 6.1 Overview of a middleware 197 6.2 Distribution models 198 6.3 Interaction using a middleware 200 6.4 Ada user code and the Ada run-time 212 6.5 Sequence of actions for synchronous calls 216 6.6 Sequence of actions for asynchronous calls 216 6.7 Overview of CORBA 222
Description: