Lập trình đồng thời và thời gian thực trong ngôn ngữ Ada

Tài liệu nghiên cứu Burns wellings concurrent and real time programming in ada, tổng hợp lý thuyết và thực hành, cung cấp kiến thức chuyên sâu về .

Trường đại học

University of York

Chuyên ngành

Computer Science

Người đăng

Ẩn danh

Thể loại

sách

2005

477
2
0

Phí lưu trữ

75 Point

Mục lục chi tiết

Preface

1. Introduction

1.2. Real-time systems

1.3. Ada’s time and clock facilities

1.5. Further reading

2. The nature and uses of concurrent programming

2.1. Uses of concurrent programming

2.4. A simple embedded system

2.6. Further reading

3. Inter-process communication

3.3. Deadlocks and indefinite postponements

3.4. System performance, correctness and reliability

3.5. Dining philosophers problem

3.6. Shared variables and protected variables

3.9. Message-based communication

3.11. Further reading

4. Task types and objects

4.2. Task activation, execution, finalisation and termination

4.5. Task creation, communication and synchronisation within task finalisation

4.6. Summary

5. The rendezvous

5.1. The basic model

5.2. The entry statement

5.3. The accept statement

5.4. The Count attribute

5.6. Three-way synchronisation

5.8. Exceptions and the rendezvous

5.10. Summary

6. The select statement and the rendezvous

6.4. The else part

6.5. The correct use of guards

6.6. The terminate alternative

6.7. The exception Program Error

6.8. Summary of the selective accept statement

6.9. Conditional and timed entry calls

6.10. Mutual exclusion and deadlocks

6.11. The dining philosophers

6.13. Summary

7. Protected objects and data-oriented communication

7.4. Entry calls and barriers

7.5. Private entries and entry families

7.6. Restrictions on protected objects

7.7. Access variables and protected types

7.8. Elaboration, finalisation and exceptions

7.10. The readers and writers problem

7.11. The specification of synchronisation agents

7.13. Volatile and atomic data

7.15. Summary

8. Avoidance synchronisation and the requeue facility

8.1. The need for requeue

8.2. Semantics of requeue

8.3. Requeuing to other entities

8.4. Real-time solutions to the resource control problem

8.5. Entry families and server tasks

8.8. Summary

9. Exceptions, abort and asynchronous transfer of control

9.2. The abort statement

9.3. Asynchronous transfer of control

9.4. Understanding the asynchronous select statement

9.5. A robust readers and writers algorithm

9.7. Summary

10. Object-oriented programming and tasking

10.1. The Ada 2005 OOP model

10.2. Tasks and interfaces

10.3. Protected types and interfaces

10.6. Further reading

11. Concurrency utilities

11.1. Communication and synchronisation abstractions

11.4. Signals

11.10. Concurrent execution abstractions

11.11. Callables and futures

11.14. Image processing example revisited

11.15. Summary

12. Tasking and systems programming

12.1. Device driving and interrupt handling

12.2. Model of interrupts

12.6. Further reading

13. Scheduling real-time systems – fixed priority dispatching

13.2. Fixed priority dispatching

13.3. Priority ceiling locking

13.4. Entry queue policies

13.5. Active priorities and dispatching policies

13.7. Further reading

14. Scheduling real-time systems – other dispatching facilities

14.1. Non-preemptive dispatching

14.2. Round-robin dispatching

14.3. Earliest deadline first dispatching

14.6. Synchronous and asynchronous task control

14.8. Further reading

15. Timing events and execution-time control

15.1. Events and event handling

15.3. Dual priority scheduling

15.4. Execution-time clocks

15.5. Execution-time timers

15.7. Task termination events

15.9. Further reading

16. Real-time utilities

16.1. Real-time task state

16.2. Real-time task release mechanisms

16.3. Periodic release mechanisms

16.4. Sporadic release mechanisms

16.5. Aperiodic release mechanisms and execution-time servers

16.6. Real-time tasks

16.7. The cruise control system example

16.8. Summary

17. Restrictions, metrics and the Ravenscar profile

17.1. Restricted tasking and other language features

17.2. The Ravenscar profile

17.3. Partition elaboration control

17.4. Examples of the use of the Ravenscar profile

17.5. Metrics and optimisations

17.7. Further reading

18. Conclusion

18.1. Support for concurrency

18.2. Support for real-time

18.3. New to Ada 2005

18.4. Outstanding issues and the future

References

Index

Tóm tắt

I. Tổng quan về lập trình đồng thời và thời gian thực trong Ada

Lập trình đồng thời và thời gian thực trong Ada là một lĩnh vực quan trọng trong phát triển phần mềm, đặc biệt cho các hệ thống nhúng và ứng dụng yêu cầu độ tin cậy cao. Ada là ngôn ngữ lập trình duy nhất được tiêu chuẩn hóa ISO, hỗ trợ lập trình đối tượng, đồng thời và thời gian thực. Ngôn ngữ này được thiết kế để phục vụ cho các ứng dụng lớn, lâu dài, nơi mà độ tin cậy và hiệu suất là rất cần thiết.

1.1. Đặc điểm nổi bật của ngôn ngữ lập trình Ada

Ada cung cấp nhiều tính năng mạnh mẽ cho lập trình đồng thời, bao gồm quản lý tài nguyên và đồng bộ hóa. Ngôn ngữ này hỗ trợ lập trình an toàn và hiệu quả, giúp lập trình viên dễ dàng xây dựng các hệ thống phức tạp.

1.2. Lịch sử phát triển của Ada

Ada đã trải qua nhiều giai đoạn phát triển từ Ada 83 đến Ada 2005, với nhiều cải tiến về tính năng và hiệu suất. Những thay đổi này giúp Ada trở thành một ngôn ngữ lý tưởng cho các ứng dụng thời gian thực.

II. Thách thức trong lập trình đồng thời và thời gian thực

Lập trình đồng thời và thời gian thực trong Ada đối mặt với nhiều thách thức, bao gồm việc quản lý tài nguyên, đồng bộ hóa và xử lý lỗi. Những vấn đề này có thể dẫn đến tình trạng deadlock hoặc hiệu suất hệ thống kém nếu không được xử lý đúng cách.

2.1. Vấn đề deadlock trong lập trình đồng thời

Deadlock xảy ra khi hai hoặc nhiều tác vụ chờ nhau để giải phóng tài nguyên, dẫn đến tình trạng không thể tiếp tục thực hiện. Việc hiểu rõ nguyên nhân và cách phòng tránh deadlock là rất quan trọng.

2.2. Quản lý tài nguyên trong hệ thống thời gian thực

Quản lý tài nguyên hiệu quả là một yếu tố quyết định trong lập trình thời gian thực. Ada cung cấp các công cụ để đảm bảo rằng tài nguyên được phân bổ và sử dụng một cách hợp lý.

III. Phương pháp lập trình đồng thời trong Ada

Ada cung cấp nhiều phương pháp để lập trình đồng thời, bao gồm tasking và synchronization. Những phương pháp này giúp lập trình viên xây dựng các ứng dụng có khả năng xử lý nhiều tác vụ cùng một lúc mà không gặp phải vấn đề về hiệu suất.

3.1. Tasking trong Ada

Tasking là một trong những tính năng chính của Ada, cho phép tạo ra các tác vụ độc lập. Điều này giúp tối ưu hóa hiệu suất và khả năng mở rộng của ứng dụng.

3.2. Synchronization trong lập trình đồng thời

Synchronization là cần thiết để đảm bảo rằng các tác vụ có thể giao tiếp và phối hợp với nhau một cách hiệu quả. Ada cung cấp nhiều cơ chế để thực hiện điều này.

IV. Ứng dụng thực tiễn của lập trình thời gian thực trong Ada

Lập trình thời gian thực trong Ada được ứng dụng rộng rãi trong nhiều lĩnh vực như hàng không, ô tô và hệ thống nhúng. Những ứng dụng này yêu cầu độ tin cậy cao và khả năng xử lý thời gian thực.

4.1. Hệ thống điều khiển hàng không

Ada được sử dụng trong các hệ thống điều khiển hàng không, nơi mà độ tin cậy và thời gian phản hồi là rất quan trọng. Các ứng dụng này thường yêu cầu các tính năng lập trình đồng thời mạnh mẽ.

4.2. Ứng dụng trong ô tô

Trong ngành công nghiệp ô tô, Ada được sử dụng để phát triển các hệ thống điều khiển an toàn và hiệu quả, giúp cải thiện trải nghiệm lái xe và đảm bảo an toàn cho người sử dụng.

V. Kết luận và tương lai của lập trình đồng thời trong Ada

Lập trình đồng thời và thời gian thực trong Ada đang ngày càng trở nên quan trọng trong phát triển phần mềm hiện đại. Với sự phát triển không ngừng của công nghệ, Ada sẽ tiếp tục đóng vai trò quan trọng trong việc xây dựng các hệ thống phức tạp và đáng tin cậy.

5.1. Xu hướng phát triển của Ada

Ada đang được cải tiến để đáp ứng nhu cầu ngày càng cao của các ứng dụng thời gian thực. Các tính năng mới sẽ giúp lập trình viên dễ dàng hơn trong việc phát triển các hệ thống phức tạp.

5.2. Tương lai của lập trình đồng thời

Với sự gia tăng của các ứng dụng yêu cầu tính đồng thời cao, lập trình đồng thời trong Ada sẽ tiếp tục phát triển và mở rộng, mang lại nhiều cơ hội cho lập trình viên.

15/07/2025

Trích đoạn nội dung tài liệu

This page intentionally left blank CO N CU RRE N T A N D RE A L - T I M E P RO G RA M M I N G I N A DA Ada is the only ISO standard, object-oriented, concurrent, real-time programming language. It is intended for use in large, long-lived applications where reliability and efficiency are essen- tial, particularly real-time and embedded systems. In this book, Alan Burns and Andy Wellings give a thorough, self-contained account of how the Ada tasking model can be used to con- struct a wide range of concurrent and real-time systems. This is the only book that focuses on an in-depth discussion of the Ada tasking model.

Following on from the authors’ earlier title ‘Concurrency in Ada’, this book brings the discussion up to date to include the new Ada 2005 language and the recent advances in real-time programming techniques. It will be of value to software professionals and advanced students of programming alike; indeed, every Ada pro- grammer will find it essential reading and a primary reference work that will sit alongside the language reference manual. ALAN B URNS is a Professor in Computer Science at the University of York. His research ac- tivities have covered a number of aspects of real-time and safety critical systems, including the assessment of languages for use in the real-time safety critical domain, distributed operating systems, the formal specification of scheduling algorithms and implementation strategies, and the design of dependable user interfaces to safety critical applications.

His teaching activities include courses in Operating Systems, Scheduling and Real-time Systems. He has authored over 370 papers and reports and 8 books, including ‘Real-time Systems and Programming Lan- guages’ (3rd Edition), ‘Concurrency in Ada’ (2nd Edition) and ‘Concurrent and Real-Time Programming in Java’. ANDY WELLINGS is a Professor of Real-Time Systems in the Computer Science Department at the University of York. He is interested in most aspects of the design and implementa- tion of real-time dependable computer systems and, in particular, in real-time programming languages and operating systems.

He is European Editor-in-Chief for the Computer Science journal ‘Software-Practice and Experience’ and a member of the International Expert Groups currently developing extensions to the Java platform for real-time, safety critical and distributed programming. He has authored over 280 papers and several books, including ‘Real-time Sys- tems and Programming Languages’ (3rd edition) and ‘Concurrency in Ada’ (2nd edition). CONCURRENT AND REAL-TIME P RO G R A M M I N G I N A DA 2 0 0 5 ALAN BURNS AND ANDY WELLINGS University of York CAMBRIDGE UNIVERSITY PRESS Cambridge, New York, Melbourne, Madrid, Cape Town, Singapore, São Paulo Cambridge University Press The Edinburgh Building, Cambridge CB2 8RU, UK Published in the United States of America by Cambridge University Press, New York www.org Information on this title: www. Wellings 2007 This publication is in copyright.

Subject to statutory exception and to the provision of relevant collective licensing agreements, no reproduction of any part may take place without the written permission of Cambridge University Press. First published in print format 2007 ISBN-13 978-0-511-29663-5 eBook (NetLibrary) ISBN-10 0-511-29663-0 eBook (NetLibrary) ISBN-13 978-0-521-86697-2 hardback ISBN-10 0-521-86697-9 hardback Cambridge University Press has no responsibility for the persistence or accuracy of urls for external or third-party internet websites referred to in this publication, and does not guarantee that any content on such websites is, or will remain, accurate or appropriate. Contents Preface page xi 1 Introduction 1 1.2 Real-time systems 3 1.3 Ada’s time and clock facilities 6 1.5 Further reading 13 2 The nature and uses of concurrent programming 15 2.1 Uses of concurrent programming 17 2.4 A simple embedded system 21 2.6 Further reading 30 3 Inter-process communication 31 3.3 Deadlocks and indefinite postponements 34 3.4 System performance, correctness and reliability 36 3.5 Dining philosophers problem 38 3.6 Shared variables and protected variables 39 3.9 Message-based communication 48 3.11 Further reading 54 v vi Contents 4 Task types and objects 55 4.2 Task activation, execution, finalisation and termination 65 4.5 Task creation, communication and synchronisation within task finalisation 77 4.6 Summary 77 5 The rendezvous 79 5.1 The basic model 79 5.2 The entry statement 81 5.3 The accept statement 83 5.4 The Count attribute 88 5.6 Three-way synchronisation 90 5.8 Exceptions and the rendezvous 93 5.10 Summary 94 6 The select statement and the rendezvous 97 6.4 The else part 107 6.5 The correct use of guards 109 6.6 The terminate alternative 111 6.7 The exception Program Error 116 6.8 Summary of the selective accept statement 118 6.9 Conditional and timed entry calls 118 6.10 Mutual exclusion and deadlocks 121 6.11 The dining philosophers 124 6.13 Summary 127 7 Protected objects and data-oriented communication 129 7.4 Entry calls and barriers 135 7.5 Private entries and entry families 139 Contents vii 7.6 Restrictions on protected objects 142 7.7 Access variables and protected types 144 7.8 Elaboration, finalisation and exceptions 146 7.10 The readers and writers problem 148 7.11 The specification of synchronisation agents 151 7.13 Volatile and atomic data 156 7.15 Summary 161 8 Avoidance synchronisation and the requeue facility 163 8.1 The need for requeue 163 8.2 Semantics of requeue 175 8.3 Requeuing to other entities 179 8.4 Real-time solutions to the resource control problem 183 8.5 Entry families and server tasks 186 8.8 Summary 194 9 Exceptions, abort and asynchronous transfer of control 195 9.2 The abort statement 198 9.3 Asynchronous transfer of control 200 9.4 Understanding the asynchronous select statement 212 9.5 A robust readers and writers algorithm 217 9.7 Summary 221 10 Object-oriented programming and tasking 223 10.1 The Ada 2005 OOP model 224 10.2 Tasks and interfaces 231 10.3 Protected types and interfaces 239 10.6 Further reading 246 11 Concurrency utilities 247 11.1 Communication and synchronisation abstractions 248 11.4 Signals 263 viii Contents 11.10 Concurrent execution abstractions 277 11.11 Callables and futures 278 11.14 Image processing example revisited 288 11.15 Summary 291 12 Tasking and systems programming 293 12.1 Device driving and interrupt handling 296 12.2 Model of interrupts 300 12.6 Further reading 316 13 Scheduling real-time systems – fixed priority dispatching 317 13.2 Fixed priority dispatching 319 13.3 Priority ceiling locking 322 13.4 Entry queue policies 327 13.5 Active priorities and dispatching policies 327 13.7 Further reading 329 14 Scheduling real-time systems – other dispatching facilities 331 14.1 Non-preemptive dispatching 331 14.2 Round-robin dispatching 332 14.3 Earliest deadline first dispatching 335 14.6 Synchronous and asynchronous task control 354 14.8 Further reading 359 15 Timing events and execution-time control 361 15.1 Events and event handling 361 15.3 Dual priority scheduling 366 Contents ix 15.4 Execution-time clocks 369 15.5 Execution-time timers 371 15.7 Task termination events 387 15.9 Further reading 389 16 Real-time utilities 391 16.1 Real-time task state 393 16.2 Real-time task release mechanisms 395 16.3 Periodic release mechanisms 397 16.4 Sporadic release mechanisms 405 16.5 Aperiodic release mechanisms and execution-time servers 407 16.6 Real-time tasks 415 16.7 The cruise control system example 419 16.8 Summary 432 17 Restrictions, metrics and the Ravenscar profile 433 17.1 Restricted tasking and other language features 433 17.2 The Ravenscar profile 436 17.3 Partition elaboration control 439 17.4 Examples of the use of the Ravenscar profile 440 17.5 Metrics and optimisations 448 17.7 Further reading 450 18 Conclusion 451 18.1 Support for concurrency 452 18.2 Support for real-time 452 18.3 New to Ada 2005 453 18.4 Outstanding issues and the future 453 References 455 Index 457 Preface The development of the Ada programming language forms a unique and, at times, intriguing contribution to the history of computer languages. As all users of Ada must know, the original language design was a result of competition between a number of organisations, each of which attempted to give a complete language definition in response to a series of documented requirements.

This gave rise to Ada 83. Following 10 years of use, Ada was subject to a complete overhaul. The resulting language, Ada 95, had a number of significant changes from its predeces- sor. A further 10 years of use has produced another version of Ada, known as Ada 2005, this time the changes are less pronounced and yet there are some key extra facilities, especially in the areas of real-time programming.

Closely linked to the development of Ada has been this book on its concurrent features. Starting out as ‘Concurrent Programming in Ada’, it became ‘Concur- rency in Ada’ when the Ada 95 version of the language was defined. There were two editions of this title. With the new features of Ada 2005, it has been decided to broaden the focus of the book to include real-time issues – hence this first edition of the new title ‘Concurrent and Real-Time Programming in Ada 2005’.

No prior knowledge of concurrent programming (in general) or of Ada tasking (in particu- lar) is assumed in this book. However, readers should have a good understanding of at least one high-level sequential programming language and some knowledge of operating system principles. This book is aimed both at professional software engineers and at students of computer science (and other related disciplines). Many millions of lines of Ada 83 and 95 code have been produced world wide, and over the next decade a wide range of new applications will be designed with Ada 2005 as the target language.

It is important that Ada programmers do not restrict themselves to a sequential subset of the language on the dubious assumption that tasking is not appropriate to their work, or for fear that the tasking model is too complex and expensive. Tasking is an integral part of the language, and programmers must be familiar with, xi xii Preface if not experienced in, its use. Due to space considerations, books that describe the entire language may not deal adequately with the tasking model; this book therefore concentrates exclusively on this model. Students studying real-time programming, software engineering, concurrent pro- gramming or language design should find this book useful in that it gives a compre- hensive description of the features that one language provides.

Ada is not merely a product of academic research (as are many concurrent programming languages) but is a language intended for actual use in industry. Its model of tasking was therefore integrated into the entire language design, and the interactions between tasking and non-tasking features were carefully defined. Consequently, the study of Ada’s model of concurrency should be included in those advanced courses men- tioned above. However, this does not imply that the full tasking model is free from controversy, has a proven formal semantic basis or is amenable to efficient imple- mentation.

The nature of these areas of ‘discussion’ are dealt with, as they arise in this book. Unlike Ada 83, which defined a single language, the Ada 95 and 2005 definitions have a core language design plus a number of domain-specific annexes. A compiler need not support all the annexes but it must support the core language. Most of the tasking features are contained in the core definition.

But there are relevant annexes that address systems programming and real-time programming. The first chapter provides a basic introduction to concurrent and real-time sys- tems and gives an overview of the clock facilities within Ada. Chapters 2 and 3 look in detail at the uses of concurrent programming and the inherent difficulties of providing inter-process communication. There is, as yet, no agreement on which primitives a concurrent programming language should support and, as a consequence, many different styles and forms exist.

In order to understand the Ada tasking model fully, it is necessary to appreciate these different approaches and the problems faced by the user of any language that supports multi-processing. The Ada task is introduced in Chapter 4 and the rendezvous and the important select statement are considered in the following two chapters. The rendezvous pro- vides a synchronous communication mechanism. Data-orientated asynchronous communication is considered in Chapter 7, together with the important abstraction of a protected object.

Nội dung được bảo vệ bản quyền — Tải xuống đầy đủ

Tài liệu "Lập trình đồng thời và thời gian thực trong Ada" cung cấp cái nhìn sâu sắc về cách thức lập trình đồng thời và quản lý thời gian thực trong ngôn ngữ lập trình Ada. Nó nhấn mạnh các khái niệm cơ bản như tác vụ, đồng bộ hóa và quản lý tài nguyên, giúp người đọc hiểu rõ hơn về cách xây dựng các ứng dụng hiệu quả và đáng tin cậy trong môi trường đa nhiệm. Những lợi ích mà tài liệu mang lại bao gồm khả năng tối ưu hóa hiệu suất của ứng dụng và cải thiện khả năng phản hồi trong các hệ thống thời gian thực.

Để mở rộng kiến thức của bạn về lập trình và ngôn ngữ lập trình, bạn có thể tham khảo tài liệu Xây dựng ngôn ngữ theo hướng tương tác. Tài liệu này sẽ giúp bạn hiểu rõ hơn về cách thiết kế ngôn ngữ lập trình theo hướng tương tác, từ đó nâng cao khả năng lập trình của bạn trong các dự án phức tạp. Hãy khám phá thêm để mở rộng kiến thức và kỹ năng của bạn trong lĩnh vực này!