Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
1© Wolfgang Emmerich, 1997
Wolfgang Emmerich
Mark Levene
C340 Concurrency:
Introduction
2© Wolfgang Emmerich, 1997
Course Overview
First half:
n by me
n Introduction to
Concurrency
n Problems
n Process Algebras
n Analysis of LTS
n Concurrent program-
ming in Java
i  l
 
I i  
l
 l
l i   
 
i  i  
Second half:
n by Mark Levene
n Parallel & Concurrent
Algorithms
n Concurrency Control
in Databases
n Probabilistic Algo-
rithms
n Non-deterministic
Algorithms
 l
  
ll l  
l i
 l
i  
ili i  l
i
i i i
l i
3© Wolfgang Emmerich, 1997
How to reach me?
Pearson Building, 402
0171 504 4413
www.cs.ucl.ac.uk/staff/w.emmerich
4© Wolfgang Emmerich, 1997
Organisation
n Lectures
• Mon 11-12 (212)
• Thu 3-4 (Anatomy LT)
• Fri  1-2 (G22)
n Tutorials/Labs
n Reading
  
   
i   
5© Wolfgang Emmerich, 1997
Bibliography
n J. Kramer & J. Magee. Concurrent Programming. Wiley.
1998 (to appear)
n A. Burns & G. Davis. Concurrent Programming. Addison
Wesley - International Computer Science Series 1993
n G.R. Andrews. Concurrent Programming: Principles and
Practice. Benjamin/Cummings, 1991
n D. Lea. Concurrent Programming in Java™: Design
Principles and Patterns. The Java Series, Addison-
Wesley, 1996
n David Flanagan.Java in a Nutshell. O’Reilly &
Associates Inc. 1996
.   . . t i . il .
 (t  )
.   . i . t i . i
l  - I t ti l t  i  i  
. . . t i : i i l  
ti . j i / i , 
. . t i  i  : i
i i l   tt .   i , i -
l , 
i  l .  i   t ll. ’ ill  
i t  I . 
6© Wolfgang Emmerich, 1997
What are you going to learn?
n Problems that occur when writing
concurrent programs
n Formalisms to specify concurrency
n Analysis techniques to reason about
correctness of specifications
n Implementation of concurrency in Java
n Practical experience (specification,
analysis, implementation) in exercises
and coursework
7© Wolfgang Emmerich, 1997
Lecture Plan
1 Introduction
2 Modelling Processes
3 Modelling Concurren-
cy in FSP
4 FSP Tutorial
5 LTSA Lab
6 Programming in Java
7 Concurrency in Java
8 Lab: Java Thread
Programming
I i
lli  
lli  
 i  
 i l
 
i  i  
 i  
  
i
9 Mutual Exclusion
10 Lab: Synchroniza-
tion in Java
11 Semaphores and
Monitors
12 Conditional Synchro-
nization
13 Fairness & Liveness
14 Safety
15 Tutorial: Model
Checking
l l i
 i
i  i  
 
i
i i l 
i i
 i   i
i l  l
i
8© Wolfgang Emmerich, 1997
Why Concurrent Programming?
n Performance gain from multiprocessing
hardware
• (parallelism)
n Increased application throughput
• (I/O call only blocks one thread)
n Increased application responsiveness
• (high priority thread for user requests).
n More appropriate structure
• (for programs which control multiple
activities and handle multiple events)
ll li
• (I/  ll l  l   t )
i  i i     .
  i  l l i l
i i i   l  l i l  
9© Wolfgang Emmerich, 1997
Engineering of Concurrent Systems
n Concurrency in safety-critical Systems
• Therac-25 failed due to race conditions
n Concurrency in mission-critical Systems
• Increasing amount of business applications
uses concurrency
n Availability of concurrency in mainstream
programming languages
• e.g. Java and Ada-95
 il     i i
I i    i  li i
 
. .   
10© Wolfgang Emmerich, 1997
Modelling Concurrency
n Analogy to Models in Engineering
n Modelling Concurrency
• Process Algebras in FSP
n Analysis of Models
• Using Labelled Transistion System Analysis
n Transformation of Models
• into Java Implementations using Threads
 l  i  
i  ll  i i   l i
i   I l i  i  
11© Wolfgang Emmerich, 1997
FSP Example
ITCH =            (scratch->STOP).
CONVERSE =        (think->talk->STOP).
||CONVERSE_ITCH = (ITCH || CONVERSE).
12© Wolfgang Emmerich, 1997
LTS Example
0 1 2 3 4 5
think talk scratch
talk think
scratch
scratch
13© Wolfgang Emmerich, 1997
n Parallelism
• Physically simultaneous processing
• Involves multiple PEs and/or independent
device operations.
n Concurrency
• Logically simultaneous processing
• Does not imply multiple processing elements
(PEs).
• Requires interleaved execution on single PE.
i ll  i l  i
I l  l i l   /  i
i  i .
i ll  i l  i
  i l  l i l  i  l
.
i  i l  i   i l  .
Definitions
14© Wolfgang Emmerich, 1997
Interleaved Model of Concurrency
Time
C
B
A
n Executing 3 processes on 1 processor:
15© Wolfgang Emmerich, 1997
Summary
n Motivation for concurrent programs
n Engineering approach to concurrency
n Finite State Processes
n Labelled Transition Systems
n Parallelism vs. concurrency
n Interleaved model of concurrency
n Next Lecture: modelling processes in FSP