Transcript Lecture1

Concurrent and Real-Time Programming in Java
 Electronic copies of course foils available via

http://www-course.cs.york.ac.uk/crt
 Course book: “Concurrent and Real-Time Programming in

Java” Andy Wellings, Wiley, 2004 (£20.99 from Amazon)
Real-Time Specification for Java (RTSJ) Versions 1.0.1 is
available from

http://www.rtj.org
© Andy Wellings, 2004
Books
RTSJ Version 0.9
© Andy Wellings, 2004
RTSJ Version 1.0.1
Other books
RTSJ Version 1.0
© Andy Wellings, 2004
RTSJ Version 0.9
Practicals
 Start week 3
 Demonstrators:
© Andy Wellings, 2004
Thursday 14.15



© Andy Wellings, 2004
Thursday 15.15


© Andy Wellings, 2004
Prerequisites
 You should already:

be a competent programmer in an imperative programming
language like C, Pascal, Ada, C++, C# etc

be able to program in sequential Java

have a good understanding of Operating System Principles, in
particular the mechanisms needed to support concurrency, e.g.
processes, semaphores, etc
© Andy Wellings, 2004
Overall Technical Aims of the Course
 To understand the basic requirements of concurrent and
real-time systems
 To understand how these requirements have influenced
the design of Java and the Real-Time Specification for Java
 To be able to program advanced concurrent real-time Java
systems
© Andy Wellings, 2004
Course Contents I
 Introduction to Course, Concurrent and Real-Time Programming







Concurrent Programming in Java
Communication and Synchronization
Motivation for, and an overview of, the RTSJ
Memory Management
Clocks and Time
Scheduling and Schedulable Objects
Asynchronous Events and Handlers
© Andy Wellings, 2004
Course Contents II
 Real-Time Threads
 Asynchronous Transfer of Control
 Resource Control
 Schedulability Analysis
 Conclusions
© Andy Wellings, 2004
Concurrent Programming
 The name given to programming notation and techniques
for expressing potential parallelism and solving the
resulting synchronization and communication problems
 Implementation of parallelism is a topic in computer
systems (hardware and software) that is essentially
independent of concurrent programming
 Concurrent programming is important because it provides
an abstract setting in which to study parallelism without
getting bogged down in the implementation details
© Andy Wellings, 2004
Why we need it
Response time in seconds
 To fully utilise the processor
10
2
1
10
0
10
-1
10
human
tape
floppy
-2
10
-3
10
-4
CD
10
10
10
10
10
10
-5
-6
-7
memory
-8
-9
processor
© Andy Wellings, 2004
Parallelism Between CPU and I/O Devices
CPU
I/O Device
Initiate I/O
Operation
Process I/O
Request
Signal Completion
Interrupt I/O
Routine
I/O Finished
Continue with
Outstanding Requests
© Andy Wellings, 2004
Why we need it
 To allow the expression of potential parallelism so that
more than one computer can be used to solve the problem
 Consider trying to find the way through a maze
© Andy Wellings, 2004
Sequential Maze Search
Concurrent Maze Search
Why we need it
 To model the parallelism in the real world
 Virtually all real-time systems are inherently concurrent —

devices operate in parallel in the real world
This is, perhaps, the main reason to use concurrency
© Andy Wellings, 2004
Air Traffic Control
Why we need it
 Alternative: use sequential programming techniques
 The programmer must construct the system as the cyclic





execution of a program sequence to handle the various
concurrent activities
This complicates the programmer's task and involves
considerations of structures which are irrelevant to the control
of the activities in hand
The resulting programs will be more obscure and inelegant
Decomposition of the problem is more complex
Parallel execution of the program on more than one processor
is more difficult to achieve
The placement of code to deal with faults is more problematic
© Andy Wellings, 2004
Terminology
 A concurrent program is a collection of autonomous
sequential processes, executing (logically) in parallel
 Each process has a single thread of control
 The actual implementation (i.e. execution) of a collection
of processes usually takes one of three forms.
Multiprogramming

processes multiplex their executions on a single processor
Multiprocessing

processes multiplex their executions on a multiprocessor system
where there is access to shared memory
Distributed Processing

processes multiplex their executions on several processors which
do not share memory
© Andy Wellings, 2004
What is a real-time system?
 A real-time system is any information processing system
which has to respond to externally generated input stimuli
within a finite and specified period

the correctness depends not only on the logical result but also
the time it was delivered

failure to respond is as bad as the wrong response!
 The computer is a component in a larger engineering system =>
EMBEDDED COMPUTER SYSTEM
 99% of all processors are for the embedded systems market
© Andy Wellings, 2004
Terminology
 Hard real-time — systems where it is absolutely imperative
that responses occur within the required deadline. E.g. Flight
control systems.
 Soft real-time — systems where deadlines are important but
which will still function correctly if deadlines are occasionally
missed. E.g. Data acquisition system.
 Firm real-time — systems which are soft real-time but in
which there is no benefit from late delivery of service.
A system may have all hard, soft and real real-time subsystems
Many systems may have a cost function associated with
missing each deadline
© Andy Wellings, 2004
A simple fluid control system
Interface
Pipe
Input flow
reading
Flow meter
Processing
Output valve
angle
Time
Computer
© Andy Wellings, 2004
Valve
A Grain-Roasting Plant
Bin
Furnace
Fuel Tank
grain
Pipe
fuel
© Andy Wellings, 2004
A Process Control System
Process
Control
Computer
Valve
Chemicals
and
Materials
Temperature
Transducer
PLANT
© Andy Wellings, 2004
Stirrer
Finished
Products
A Production Control System
Production
Control
System
Finished
Products
Parts
Machine Tools
© Andy Wellings, 2004
Manipulators
Conveyor Belt
A Command and Control System
Command
Post
Command and Control
Computer
Temperature, Pressure, Power and so on
Terminals
© Andy Wellings, 2004
Sensors/Actuators
A Typical Embedded System
Real-Time
Clock
Algorithms for
Digital Control
Interface
Engineering
System
Data Logging
Remote
Monitoring System
Data Retrieval
and Display
Display
Devices
Database
Operator’s
Console
© Andy Wellings, 2004
Operator
Interface
Real-Time Computer
Characteristics of a RTS
 Large and complex — vary from a few hundred lines of
assembler or C to 20 million lines of Ada estimated for the
Space Station Freedom
 Concurrent control of separate system components —
devices operate in parallel in the real-world; better to
model this parallelism by concurrent entities in the
program
 Facilities to interact with special purpose hardware — need
to be able to program devices in a reliable and abstract
way
© Andy Wellings, 2004
Characteristics of a RTS
 Extreme reliability and safe — embedded systems typically
control the environment in which they operate; failure to
control can result in loss of life, damage to environment or
economic loss
 Guaranteed response times — we need to be able to
predict with confidence the worst case response times for
systems; efficiency is important but predictability is
essential
© Andy Wellings, 2004
Real-time Programming Languages
 Assembly languages
 Sequential systems implementation languages — e.g.





RTL/2, Coral 66, Jovial, C.
Both normally require operating system support.
High-level concurrent languages. Impetus from the
software crisis. e.g. Ada, Chill, Modula-2, Mesa, Java.
No operating system support!
We will focus on Java and the Real-Time Specification for
Java
See Burns, Wellings, Real-Time Systems and Programming
Languages, 3rd Edition, 2001, Addison Wesley for a
general discussion on other languages and operating
systems
© Andy Wellings, 2004
Java Architecture
JBC
JBC
JBC
Hardware
JVM
Standalone
JVM
Real-time Operating
System
© Andy Wellings, 2004
JVM
Summary I
 The motivations for concurrent programming have been
presented:



fully utilize the processor
allow parallel execution
model real world parallelism
 Two main classes of real-time systems have been
identified:


hard real-time systems
soft real-time systems
© Andy Wellings, 2004
Summary II
 The basic characteristics of a real-time or embedded
computer system are:







largeness and complexity,
manipulation of real numbers,
extreme reliability and safety,
concurrent control of separate system components,
real-time control,
interaction with hardware interfaces,
efficient implementation.
© Andy Wellings, 2004
Further Reading
 Chapter 1 of Burns and Wellings, “Real-Time Systems and
Programming Languages”, 3rd Edition, 2001 (in library)
© Andy Wellings, 2004