Muutke küpsiste eelistusi

E-raamat: Design of Multithreaded Software - The Entity-Life Modeling Approach: The Entity-Life Modeling Approach [Wiley Online]

  • Formaat: 320 pages, Charts: 78 B&W, 0 Color; Drawings: 2 B&W, 0 Color
  • Ilmumisaeg: 15-Feb-2011
  • Kirjastus: John Wiley & Sons Inc
  • ISBN-10: 470904917
  • ISBN-13: 9780470904916
  • Wiley Online
  • Hind: 116,25 €*
  • * hind, mis tagab piiramatu üheaegsete kasutajate arvuga ligipääsu piiramatuks ajaks
  • Formaat: 320 pages, Charts: 78 B&W, 0 Color; Drawings: 2 B&W, 0 Color
  • Ilmumisaeg: 15-Feb-2011
  • Kirjastus: John Wiley & Sons Inc
  • ISBN-10: 470904917
  • ISBN-13: 9780470904916
This book assumes familiarity with threads (in a language such as Ada, C#, or Java) and introduces the entity-life modeling (ELM) design approach for certain kinds of multithreaded software. ELM focuses on "reactive systems," which continuously interact with the problem environment. These "reactive systems" include embedded systems, as well as such interactive systems as cruise controllers and automated teller machines.

Part I covers two fundamentals: program-language thread support and state diagramming. These are necessary for understanding ELM and are provided primarily for reference. Part II covers ELM from different angles. Part III positions ELM relative to other design approaches.

Foreword xv
Preface xvii
I Foundations 1(104)
1 Introduction
3(22)
1.1 Entity-Life Modeling
3(2)
1.1.1 Reactive Systems
5(1)
1.2 Overview of This Book
5(1)
1.3 Multithreading
6(3)
1.3.1 Preemptive and Nonpreemptive Threading
7(1)
1.3.2 Using Threads
7(2)
1.3.2.1 Thread Scheduling
8(1)
1.3.2.2 Message Passing
8(1)
1.3.2.3 A Different Mindset
9(1)
1.4 Engineering the Intangible
9(4)
1.4.1 Software Architecture
10(1)
1.4.1.1 Thread Architecture
10(1)
1.4.2 Conceptual Integrity
11(1)
1.4.2.1 The Key Idea of an Architecture
12(1)
1.4.3 Analogical Modeling
12(1)
1.5 The Development Process
13(4)
1.5.1 ELM in the Development Process
14(1)
1.5.2 Analysis and Design
15(1)
1.5.3 Design Upfront
15(2)
1.5.3.1 Refactoring
17(1)
1.6 Unified Modeling Language™
17(5)
1.6.1 Requirements Elicitation: Use Cases
18(1)
1.6.1.1 Actors and Use Cases in Reactive Systems
18(1)
1.6.1.2 Using State Modeling to Capture Use-Case Flows
19(1)
1.6.2 UML's Logical View
19(6)
1.6.2.1 Static Structure: Class Diagrams
19(1)
1.6.2.2 Dynamic Structure: Sequence and Communication Diagrams
20(2)
1.7 Conclusion
22(3)
2 Support for Multithreading
25(46)
2.1 Introduction
25(14)
2.1.1 Basic Multithreading and Synchronization Concepts
26(2)
2.1.1.1 Threads
26(1)
2.1.1.2 Safe Objects and Synchronization
27(1)
2.1.2 Multithreading in High-Level Languages
28(3)
2.1.2.1 Java
29(1)
2.1.2.2 Ada
29(2)
2.1.3 Threads and Processes
31(1)
2.1.4 Exclusion and Condition Synchronization
31(7)
2.1.4.1 Use of Exclusion Synchronization
32(3)
2.1.4.2 Condition Synchronization
35(3)
2.1.5 Interrupt Handling
38(1)
2.1.5.1 Interrupt Priorities
38(1)
2.1.6 Visualizing Threads
39(1)
2.2 Concurrency in Java™
39(13)
2.2.1 Defining and Starting Java Threads
39(1)
2.2.1.1 The sleep Statement
40(1)
2.2.2 Synchronized Objects in Java
40(2)
2.2.2.1 Synchronized Blocks
41(1)
2.2.2.2 Nested, Critical Sections in Java
42(1)
2.2.3 Condition Synchronization in Java
42(3)
2.2.3.1 Placement of the Wait Loop
43(1)
2.2.3.2 Notifying Waiting Threads
44(1)
2.2.3.3 Timing Out the Wait
45(1)
2.2.4 Controlling Access to Shared Domain Resources
45(1)
2.2.4.1 Semaphore Solution
45(1)
2.2.4.2 Monitor Solution
46(1)
2.2.5 Real-Time Java (RTSJ)
46(6)
2.2.5.1 RTSJ Thread Classes
47(1)
2.2.5.2 RTSJ Interrupt Handling
47(1)
2.2.5.3 Time and Timers in RTSJ
48(1)
2.2.5.4 RTSJ Memory Areas
48(1)
2.2.5.5 Limiting Priority Inversion in RTSJ
49(1)
2.2.5.6 RTSJ: Wait-Free Queues
49(1)
2.2.5.7 Asynchronous Transfer of Control in RTSJ
50(2)
2.3 Concurrency in Ada
52(13)
2.3.1 Defining and Starting Tasks
52(3)
2.3.1.1 Declaration of Single Tasks and Task Types
52(1)
2.3.1.2 Instantiation of Task Types
52(1)
2.3.1.3 Task Activation
53(1)
2.3.1.4 Task Priorities
54(1)
2.3.1.5 The delay Statement
54(1)
2.3.1.6 Exceptions in Tasks
55(1)
2.3.2 Protected Objects
55(7)
2.3.2.1 Protected Interfaces
57(1)
2.3.2.2 Requeuing
58(1)
2.3.2.3 Conditional and Timed Entry Calls
59(1)
2.3.2.4 Interrupt Handling
59(1)
2.3.2.5 Timing Events
60(1)
2.3.2.6 Controlling Access to Shared Domain Resources
61(1)
2.3.3 Asynchronous Transfer of Control
62(2)
2.3.3.1 Example: Bumping an FMS Job
63(1)
2.3.4 Rendezvous
64(1)
2.4 Pthreads
65(3)
2.4.1 Managing Pthreads
65(1)
2.4.1.1 Example of Pthreads
66(1)
2.4.2 Mutex Variables and Exclusion Synchronization
66(1)
2.4.2.1 Example of Pthreads and Mutexes
66(1)
2.4.3 Condition Variables and Condition Synchronization
67(1)
2.4.4 Pthreads: Conclusion
68(1)
2.5 Conclusion
68(1)
Exercises
68(3)
3 State Modeling
71(34)
3.1 Introduction
71(1)
3.1.1 State Modeling and Object Orientation
72(1)
3.2 State-Modeling Terminology
72(3)
3.2.1 States and Events
73(2)
3.2.1.1 Time Events
74(1)
3.2.1.2 Determinism
74(1)
3.3 Basic State Modeling
75(9)
3.3.1 A Simple Example
75(1)
3.3.2 Guard Conditions
76(3)
3.3.2.1 Guard Conditions Based on Modeled-Entity Attributes
77(1)
3.3.2.2 Ambient Guard Conditions
78(1)
3.3.2.3 Complex Guard Conditions
78(1)
3.3.2.4 Example: Traffic Light
78(1)
3.3.2.5 State Machines Associated with Aggregate Entities
79(1)
3.3.3 State Tables
79(1)
3.3.4 Actions and Activities
80(4)
3.3.4.1 Actions
80(2)
3.3.4.2 Activities
82(1)
3.3.4.3 Actions or Activities?
83(1)
3.3.4.4 Actions on Timers
83(1)
3.3.4.5 Actions on Other Attribute Variables
84(1)
3.3.5 Multiple Events with the Same Effect
84(1)
3.3.6 Basic State Modeling: Summary
84(1)
3.4 Superstates
84(8)
3.4.1 Exceptional Events
86(1)
3.4.2 Arrows between Substate and Superstate Border
87(1)
3.4.2.1 Superstates for Reducing Clutter
87(1)
3.4.3 Activities and Internal Actions for Superstates
87(1)
3.4.4 Orthogonal Composition
88(3)
3.4.4.1 Orthogonal States and Multithreading
89(1)
3.4.4.2 Know Your States!
90(1)
3.4.5 Additional Superstate Concepts
91(1)
3.4.5.1 History Marker
91(1)
3.4.5.2 Overlapping Superstates
91(1)
3.5 Examples
92(3)
3.5.1 Whole-House Fan
92(1)
3.5.2 Code Lock
92(2)
3.5.3 Car Window
94(1)
3.6 State Modeling in Practice
95(3)
3.6.1 State Diagram Layout
96(1)
3.6.1.1 Conversations with Materials; Backtalk
96(1)
3.6.2 State Names
96(1)
3.6.3 Consistent Point of View
97(1)
3.6.4 Time Scale of State Models
97(1)
3.6.4.1 Near Instantaneity
98(1)
3.6.4.2 State Models of Devices with Embedded Software
98(1)
3.7 State Machine Implementation
98(4)
3.7.1 Explicit State Representation
99(2)
3.7.1.1 Alternate Implementation: A Single Handler for All Events
100(1)
3.7.1.2 Other Implementations of Explicit State Representation
100(1)
3.7.2 Implicit State Representation
101(1)
3.8 Conclusion
102(1)
Exercises
102(3)
II The ELM Way 105(126)
4 Entity-Life Modeling
107(32)
4.1 Introduction
107(4)
4.1.1 Concurrency Structures in the Problem Domain
108(1)
4.1.2 Thread Architectures
109(2)
4.1.2.1 Analogical Modeling
110(1)
4.1.2.2 Few But Significant Thread Types
110(1)
4.2 Modeling Software on Event Threads
111(12)
4.2.1 ELM Rationale
111(3)
4.2.1.1 Object-Oriented Modeling
111(1)
4.2.1.2 Modeling in the Time Dimension
112(1)
4.2.1.3 Time Events
113(1)
4.2.1.4 Events Shared by Problem and Software Domains
113(1)
4.2.2 Event Threads and Event-Thread Models Defined
114(3)
4.2.2.1 Data-Entry Example
115(1)
4.2.2.2 Impractical and Counterintuitive Event-Thread Models
116(1)
4.2.2.3 Exceptional Events in a Thread
116(1)
4.2.3 Concurrency Levels and Optimal Event-Thread Models
117(3)
4.2.3.1 Coincidental Simultaneity
118(1)
4.2.3.2 Concurrency Levels and Optimality
119(1)
4.2.3.3 Nonoptimal Event-Thread Models
119(1)
4.2.3.4 Multiprocessors
120(1)
4.2.4 Latitude for the Designer
120(1)
4.2.4.1 Accidental Constraints
121(1)
4.2.4.2 Many Simultaneous Occurrences
121(1)
4.2.5 Design Based on Event Threads
121(2)
4.2.5.1 Design Patterns for Implementing Threads
122(1)
4.3 Discovering and Choosing Event-Thread Models
123(5)
4.3.1 Identifying Individual Entities and Event Threads
123(2)
4.3.1.1 Operator Threads
123(1)
4.3.1.2 Periodic Threads
124(1)
4.3.1.3 Long-Lived Threads
125(1)
4.3.2 Example of Thread Identification: Elevator System
125(3)
4.4 Event-Thread Patterns for Resource Sharing
128(5)
4.4.1 Simultaneous Exclusive Access to Multiple Resources
129(1)
4.4.2 Example: Jukebox
130(1)
4.4.2.1 Resource-User-Thread Model: A Thread per Customer
130(1)
4.4.2.2 Resource-Guard-Thread Model: A Thread per Panel
130(1)
4.4.2.3 Comparison of Thread Models and Architectures
130(1)
4.4.3 Example: Queuing System for a Bank Office
131(8)
4.4.3.1 Resource-User-Thread Model: A Thread per Customer
131(1)
4.4.3.2 Resource-Guard-Thread Model: A Thread per Teller
132(1)
4.4.3.3 Comparison of Thread Models and Designs
132(1)
4.5 Portraying the World in Software
133(1)
4.6 Conclusion
134(1)
Appendix 4A: Summary of Terms
135(1)
Exercises
136(3)
5 Design Patterns Based on Event Threads
139(34)
5.1 Introduction
139(3)
5.1.1 Software Activities and Nominal Activities
140(2)
5.1.1.1 Particular Kinds of Software Activity
140(2)
5.1.2 A Note on Complexity
142(1)
5.2 State Machines without Software activities
142(5)
5.2.1 Examples
143(4)
5.2.1.1 Example: A Simple Fan
143(1)
5.2.1.2 Example: Window Elevator for a Car
143(2)
5.2.1.3 Example: Bicycle Odometer
145(2)
5.3 Sequential-Activities Design Pattern
147(4)
5.3.1 Implicit State in Sequential-Activities Threads
147(2)
5.3.2 Sensing Events That May Change the State
149(1)
5.3.3 Example: Odometer as a Sequential-Activities Thread
149(2)
5.4 Concurrent-Activities Design Pattern
151(10)
5.4.1 State Machine Safe Objects Revisited
151(2)
5.4.2 Activity Threads
153(2)
5.4.2.1 Multiple Instances of a State Machine Safe Class
153(1)
5.4.2.2 Communication with State Machine Safe Object
153(1)
5.4.2.3 Activity-Thread Creation
154(1)
5.4.3 Examples
155(6)
5.4.3.1 Cruise Controller
155(3)
5.4.3.2 Example: Weather Buoy
158(3)
5.5 Communicating State Machines
161(8)
5.5.1 Communicating State Machines without Activities
161(5)
5.5.1.1 Example: Toy Car Factory
161(3)
5.5.1.2 Example: Baggage-Handling System
164(2)
5.5.2 Communicating State Machines with Activities
166(3)
5.5.2.1 Production Line Workstation
166(3)
5.5.3 Broader Use of Activity Threads
169(1)
5.6 Conclusion
169(1)
Exercises
170(3)
6 Event-Thread Patterns for Resource Sharing
173(24)
6.1 Introduction
173(1)
6.1.1 Duality of the Patterns
174(1)
6.2 Resource-User-Thread Pattern
174(3)
6.2.1 Exclusive Access to Domain Objects
175(2)
6.2.1.1 Implementation of Semaphores for Domain Objects
175(2)
6.2.1.2 Implementation of Monitors for Domain Objects
177(1)
6.2.2 Programming Style
177(1)
6.3 The Resource-Guard-Thread Pattern
177(2)
6.3.1 Queuing
178(1)
6.3.2 Resource-Independent Processing
178(1)
6.3.3 Guard Threads Implemented as Concurrent Activities
178(1)
6.4 Choosing and Combining Patterns
179(2)
6.4.1 Resource-Guard Threads Doubling as Resource Users
179(1)
6.4.1.1 One Resource-User Event Thread—A Series of Control Threads
180(1)
6.4.2 Choosing Resource-User or Resource-Guard Threads
180(1)
6.5 Examples with Dual Solutions
181(7)
6.5.1 Remote Temperature Sensor
181(2)
6.5.1.1 RTS: Resource-User-Thread Solution
182(1)
6.5.1.2 RTS: Resource-Guard-Thread Solution
183(1)
6.5.1.3 RTS: Comparison of the Solutions
183(1)
6.5.2 Home-Heating System
183(3)
6.5.2.1 Home Heater: Resource-User-Thread Solution
184(1)
6.5.2.2 Home Heater: Dual Solution
185(1)
6.5.3 Automated Store
186(2)
6.5.3.1 Resource-User-Thread Solution
186(1)
6.5.3.2 Resource-Guard-Thread Solution
187(1)
6.6 Data Stream Processing
188(2)
6.6.1 Surveillance Radar Problem
188(1)
6.6.2 MIDI Problem
189(1)
6.6.2.1 Programmable Patch Bay
189(1)
6.7 Repository Problems
190(3)
6.7.1 Multielevator System
190(2)
6.7.1.1 Solution Sketch
191(1)
6.7.1.2 Concurrency Levels in the Elevator Problem
192(1)
6.7.2 Traffic Light System
192(1)
6.7.3 Repository Problem Solutions
192(1)
6.8 Conclusion
193(1)
Exercises
194(3)
7 Simultaneous Exclusive Access to Multiple Resources
197(34)
7.1 Introduction
197(1)
7.2 The Deadlock Problem
198(8)
7.2.1 Determining That a System is Deadlock Free
199(2)
7.2.2 Deadlock Prevention
201(4)
7.2.2.1 Resource Ordering
202(1)
7.2.2.2 Limiting the Number of Entities
202(1)
7.2.2.3 Avoiding Indefinite Waiting
203(2)
7.2.3 Dining Philosophers' Problem
205(1)
7.2.3.1 Deadlock Prevention in the Philosophers' Problem
205(1)
7.3 Case Studies
206(14)
7.3.1 Automated Train Switchyard
206(4)
7.3.1.1 Deadlock Analysis of the Switchyard
208(1)
7.3.1.2 Optimization
209(1)
7.3.1.3 Realism
209(1)
7.3.1.4 Hump Yards
210(1)
7.3.2 Flexible Manufacturing System
210(8)
7.3.2.1 Deadlock Prevention in the FMS
212(1)
7.3.2.2 Job-Thread Solution for the FMS
213(2)
7.3.2.3 Workstation-Thread Solution for the FMS
215(2)
7.3.2.4 Other FMS Solutions
217(1)
7.3.3 AGV System Simulation
218(2)
7.3.3.1 Solution Sketch for the AGV System
218(1)
7.3.3.2 Complications
219(1)
7.4 Heuristics
220(1)
7.4.1 Entities Driving the Process
220(1)
7.4.1.1 Anthropomorphism?
221(1)
7.5 More on Deadlock and Its Prevention
221(3)
7.5.1 Deadlock with and without Threads
221(1)
7.5.2 Deadlock Involving Internal Software Resources
222(1)
7.5.3 Expanding an ELM Architecture
222(1)
7.5.4 Problems without Apparent Resources
223(1)
7.5.5 Acquiring All Resources Ahead of Time
224(1)
7.6 Conclusion
224(1)
Exercises
225(6)
III Background and Discussion
8 Real Time Software Architectures and Data-Flow Design Approaches
231(26)
8.1 Introduction
231(1)
8.2 Real-Time Architectures
232(6)
8.2.1 Cyclic Executive
232(2)
8.2.1.1 Cyclic Executive Implementations with Threads
233(1)
8.2.2 Periodic Threads
234(2)
8.2.2.1 Rate-Monotonic Scheduling
234(2)
8.2.3 Dynamically Scheduled Threads
236(1)
8.2.4 Requirements Representations versus Architectures
237(1)
8.3 Data-Flow Design Approaches
238(17)
8.3.1 Structured Analysis
238(4)
8.3.1.1 Strengths and Weaknesses of Structured Analysis
239(1)
8.3.1.2 Design and Implementation Based on Data Flow
240(1)
8.3.1.3 Real-Time Structured Analysis
241(1)
8.3.2 Data-Flow Threading
242(6)
8.3.2.1 Mascot
242(1)
8.3.2.2 Data Flow and Object Orientation
243(1)
8.3.2.3 Advantages of Data-Flow Threading
243(1)
8.3.2.4 Drawbacks of Data-Flow Threading
244(4)
8.3.3 Example Approach: COMET
248(2)
8.3.3.1 Steps 1 and 2: Designing High-Level Architecture; Structuring Subsystems
249(1)
8.3.3.2 Step 4: Structuring the Threads
249(1)
8.3.3.3 Step 6: Designing Classes
250(1)
8.3.3.4 Step 7: Detailed Design
250(1)
8.3.4 COMET Solution for the Cruise Controller
250(8)
8.3.4.1 Cruise Controller Software Architecture
251(1)
8.3.4.2 Thread Structuring
252(1)
8.3.4.3 Thread Interfaces
252(1)
8.3.4.4 Comparison with ELM
253(2)
8.4 Conclusion
255(2)
9 The Origins of Entity-Life Modeling
257(22)
9.1 Introduction
257(1)
9.2 Early Experiences with Software Development
258(2)
9.2.1 Systems Programming
259(1)
9.2.2 Multithreading
259(1)
9.3 The Jackson Methods
260(10)
9.3.1 Jackson Structured Programming
261(5)
9.3.1.1 Structure of Data
261(1)
9.3.1.2 Program Control Structure
262(1)
9.3.1.3 Programs Based on Combined Data Tree Diagrams
263(1)
9.3.1.4 Structure Clashes
264(1)
9.3.1.5 Real-Life JSP Example
265(1)
9.3.1.6 The Difficult and the Simplistic
265(1)
9.3.2 Implicit State Representation
266(1)
9.3.3 Explicit State Representation
267(1)
9.3.3.1 Inversion with Respect to Event Threads
267(1)
9.3.4 JSD, Threading, and ELM
268(1)
9.3.5 Reconciling the Object and Process Models
269(1)
9.4 Formal Models and Methods
270(2)
9.4.1 Process Algebra
270(1)
9.4.2 Other Formalism
270(1)
9.4.3 The Need for Formalism
271(1)
9.4.4 Concurrency in Other Languages
271(1)
9.5 Software Patterns
272(2)
9.5.1 ELM Patterns
273(1)
9.5.1.1 Event-Thread Patterns for Resource Sharing
273(1)
9.5.1.2 State Machine—Related Design Patterns
274(1)
9.5.1.3 Distinction between Event-Thread and Design Patterns
274(1)
9.6 Conclusion
274(1)
Exercises
275(4)
Glossary 279(4)
References 283(10)
Index 293
Bo I. Sandén, PhD, serves as Professor of Computer Science at Colorado Technical University. He has also taught at George Mason University in Fairfax, Virginia. Prior to his teaching career, Dr. Sandén worked at Phillips Elektronikindustrier in Stockholm, Sweden, and has significant professional experience as a systems analyst, project manager, programmer, and consultant. He devotes his research activities primarily to software design and has published extensively on Jackson system development, concurrency in Ada and Java, and entity-life modeling.