Upload
tobias-payne
View
217
Download
2
Tags:
Embed Size (px)
Citation preview
ICT301
• 10 credits module• 7 lectures – selected difficult topics• 6 tutorials – practical sessions • 3 TMAs
ICT301
• 10 credits module• 7 lectures – selected difficult topics• 6 tutorials – practical sessions • 3 TMAs• Lecturer and tutors• Electronic conferences• Examination• References Bacon
TanenbaumAndrews
ICT301
• Block 1 – The Foundations– Nature of concurrent systems
– Hardware and operating systems support
– Processes, multi-threading
Programming language needed
ICT301
• Block 2 – Inter-process Communications– Shared and non shared data
– Shared and non shared memory
– Problems and issues
Not fact-based• Requires understanding
ICT301
• Block 3 – Application Considerations– System viability
– Transactions
– Distributed databases
– Standards and mini case study
Concurrent Systems
Systems with several processes that:• contribute to overall objective
• independent
• cooperate among themselves – exchange data– synchronise actions
• compete for resources
• respond to external events – interact with external environment
1
4
2
3
elevator 2 discharging passengers at level 1
level 1
level 2
level 3
level 4
level 5elevator 1 answers the call at level 4 to go up because someone will be getting off from it at this level
elevator 4 answers a call to go down
level 6
level 7 elevator 3 bypasses a call at level 4 to go up because elevator 1 will be stopping at that level
1
4
2
3
level 1
level 2
level 3
level 4
level 5
level 6
level 7
The system is dynamic and concurrent
Service zone
Service zone
Service zone
Service zone
Concurrent Systems
• How would the Java program looks like?
class ElevatorController
{ public static void main(String args[ ])
{
use for loop ?
}
}
Concurrent Systems
• How would the Java program looks like?
class ElevatorController
{ public static void main(String args[ ])
{
use for loop ?
}
}independentcooperate
exchange datasynchronise actions
compete for resourcesrespond to external events
interact with external environment
Concurrent Systems
• Inherently concurrent systems
– Concurrent by nature
• Potentially concurrent systems
– Not concurrent by nature
– But can be implemented as concurrent systems
Inherently Concurrent Systems
• Typical inherently concurrent systems
– Real-time and embedded systems
– Databases and transaction processing systems
– Operating systems
Inherently Concurrent Systems
• Typical inherently concurrent systems
– Real-time and embedded systems• Hard real time systems
• Soft real time systems
– Databases and transaction processing systems
– Operating systems
Aircraft Flight Controls
Real time? Information up to date
Hard or soft? Response time critical
Aircraft Flight Controls
Real time? Information up to date
Hard or soft? Response time critical
Inherently Concurrent Systems
• Typical inherently concurrent systems
– Real-time and embedded systems• Hard real time systems
• Soft real time systems
– Databases and transaction processing systems
– Operating systems
Banking: ATM system
Real time?
Hard or soft?
Balance inquiry Cash withdrawal
Inherently Concurrent Systems
• Typical inherently concurrent systems
– Real-time and embedded systems
– Databases and transaction processing systems
– Operating systems
Recall our get-rich-quick story
Bank accountsATM GIRO
Inherently Concurrent Systems
• Typical inherently concurrent systems
– Real-time and embedded systems
– Databases and transaction processing systems
– Operating systems
Inherently Concurrent Systems
• Typical inherently concurrent systems
– Real-time and embedded systems
– Databases and transaction processing systems
– Operating systems
• Single user
Disk
Printer
Processor
Memory
Screen
Keyboard
Inherently Concurrent Systems
• Typical inherently concurrent systems
– Real-time and embedded systems
– Databases and transaction processing systems
– Operating systems
• Single user
• Multi-users
Disk
Printer
Processor
Memory
Screen
Keyboard
Screen
Keyboard
Screen
Keyboard
Disk
Disk
Processor
Plotter
Inherently Concurrent Systems
• Typical inherently concurrent systems
– Real-time and embedded systems
– Databases and transaction processing systems
– Operating systems
• Single user
• Multi-users
• Networked users
€
€
€
€
€
€
€
€
databaseserver
databaseserver
print server
workstation workstation workstation workstation
print server
1
2
3
4
1
2
3
4
Potentially Concurrent Systems
• Not concurrent by nature
• Advantageous to implement concurrent processing
• Usually in situations where
– large amount of data
– large amount of processing
– real-time need
– parallel processing possible
Potentially Concurrent Systems
• Ways to implement concurrent processing
– Replicated code with partitioned data
– Partitioned code with duplicated data
– Pipelined processing
– Tree-structured algorithms
Potentially Concurrent Systems
• Ways to implement concurrent processing
– Replicated code with partitioned data
– Partitioned code with duplicated data
– Pipelined processing
– Tree-structured algorithms
Program that coordinates the
processing
Codes that process data
Portion of data
Codes that process data
Portion of data
Codes that process data
Portion of data
. . . . . .
Potentially Concurrent Systems
• Ways to implement concurrent processing
– Replicated code with partitioned data
– Partitioned code with duplicated data
– Pipelined processing
– Tree-structured algorithms Matrix operations
36786817
25964473
52389571
57824723
Potentially Concurrent Systems
• Ways to implement concurrent processing
– Replicated code with partitioned data
– Partitioned code with duplicated data
– Pipelined processing
– Tree-structured algorithms
Marked by examiner A
Batch 1
Potentially Concurrent Systems
• Ways to implement concurrent processing
– Replicated code with partitioned data
– Partitioned code with duplicated data
– Pipelined processing
– Tree-structured algorithms
Marked by examiner A
Marked by examiner B
Batch 1
Marked by examiner A
Batch 2
Potentially Concurrent Systems
• Ways to implement concurrent processing
– Replicated code with partitioned data
– Partitioned code with duplicated data
– Pipelined processing
– Tree-structured algorithms
Marked by examiner A
Marked by examiner B
Reviewed by moderator
Batch 1
Marked by examiner A
Marked by examiner B
Batch 2
Marked by examiner A Batch 3
Potentially Concurrent Systems
• Ways to implement concurrent processing
– Replicated code with partitioned data
– Partitioned code with duplicated data
– Pipelined processing
– Tree-structured algorithms
Marked by examiner A
Marked by examiner B
Reviewed by moderator
Checked by checker
Batch 1
Marked by examiner A
Marked by examiner B
Reviewed by moderator
Batch 2 . . .
Marked by examiner A
Marked by examiner B Batch 3 . . .
Marked by examiner A Batch 4 . . .
Potentially Concurrent Systems
• Ways to implement concurrent processing
– Replicated code with partitioned data
– Partitioned code with duplicated data
– Pipelined processing
– Tree-structured algorithms
3 1
5
8
2 7 3
6 8
7 5
9
4 8
3
2
5
4
2
8
5 7
1
5 2
8
6 4
1
7
2
3 4
9
9
3 1
5
8
2 7 3
6 8
7 5
9
4 8
3
2
5
4
2
8
5 7
1
5 2
8
6 4
1
7
2
3 4
9
7
3 1
5
8
2 7 3
6 8
7 5
9
4 8
3
2
5
4
2
8
5 7
1
5 2
8
6 4
1
7
2
3 4
9
Potentially Concurrent Systems
• Ways to implement concurrent processing
– Replicated code with partitioned data
– Partitioned code with duplicated data
– Pipelined processing
– Tree-structured algorithms
7
3 1
5
8
2 7 3
6 8
7 5
9
4 8
3
2
5
4
2
8
5 7
1
5 2
8
6 4
1
7
2
3 4
9
7
3 1
8
5
8
2 7 3
6 8
7 5
9
4 8
3
2
5
4
2
8
5 7
1
5 2
8
6 4
1
7
2
3 4
9
7
3 1
6
5
8
2 7 3
6 8
7 5
9
4 8
3
2
5
4
2
8
5 7
1
5 2
8
6 4
1
7
2
3 4
9
Potentially Concurrent Systems
• Ways to implement concurrent processing
– Replicated code with partitioned data
– Partitioned code with duplicated data
– Pipelined processing
– Tree-structured algorithms
stage 1
stage 2
stage 3
stage 4
Potentially Concurrent Systems
Fields for Applications
– Artificial intelligence
– Graphical imaging
– Natural phenomena analysis
– Engineering analysis
– Mathematical modelling
Basic Computer Architecture
Recall operating systems
– inherently concurrent
– closer look at what it has to do
Disk
Printer
Processor
Memory
Screen
Keyboard
Typical architecture
Basic Computer Architecture
• CPU execution cycle
– von Neumann architecture
update instruction pointer
execute instruction
fetch instruction
decode instruction
Machine instructions
Instruction 1Instruction 2Instruction 3Instruction 4Instruction 5
. . .
The big speed difference
Consider a 2 GHz CPU
– Two thousand million cycles per second
Consider human typing at 10 characters per second
The big speed difference
Consider a 2 GHz CPU
– Two thousand million cycles per second
Consider human typing at 10 characters per second
If CPU works at 1 cycle per second,
human would be typing at one character every six years.
Ratio is 200,000,000 to 1
The big speed difference
Consider a 2 GHz CPU
– Two thousand million cycles per second
Consider a hard-disk transferring data at 10 megabytes per second
The big speed difference
Consider a 2 GHz CPU
– Two thousand million cycles per second
Consider a hard-disk transferring data at 10 megabytes per second
For every byte read from disk, CPU does about 200 cycles
Ratio is 200 to 1
• Two implications arising from big difference in speed:
1. We need buffers
2. The CPU should be deployed elsewhere
The big speed difference
• Two implications arising from big difference in speed:
1. We need buffers
So the CPU does not have to wait while IO operations takes place
The big speed difference
• Two implications arising from big difference in speed:
1. We need buffers
2. The CPU should be deployed elsewhere
This means dividing its attention among many tasks
The big speed difference
Basic Computer Architecture
• Dividing CPU’s attention among many tasks
time-slicing
task 2task 3task 1task 2task 1
4321 765
. . .
. . .time interval
Basic Computer Architecture
• Dividing CPU’s attention among many tasks
time-slicing
task 1task 1 . . .
4321 765 . . .time interval
task 2task 2 . . .task 3 . . .
task 1
task 2
task 3
Basic Computer Architecture
• Dividing CPU’s attention among many tasks
And we need interrupts
Task 1 Interrupt service routine
Task 2
Basic Computer Architecture
• Dividing CPU’s attention among many tasks
And we need interrupts
Time allocated to a task is up
Higher priority request from another program
Request to update the real time clock
Exceptions encountered in a program
Completion of an IO operation
Basic Computer Architecture
• Dividing CPU’s attention among many tasks
Interrupts involve context switch
CPU
data of program
instruction pointer
Main memory
interrupt service routine
Before an interrupt
a program
Basic Computer Architecture
• Dividing CPU’s attention among many tasks
Interrupts involve context switch
CPU
data of interrupt service routine
instruction pointer
Main memory
interrupt service routine
After an interrupt
a program
Basic Computer Architecture
• Dividing CPU’s attention among many tasks
Interrupts involve context switch
saving the status of executing
program to main memory
CPU
instruction register
instruction pointer
data registersdata for
executing interrupt service
routine
Basic Computer Architecture
• Dividing CPU’s attention among many tasks
An alternative to interrupts is polling
Basic Computer Architecture
• Dividing CPU’s attention among many tasks
An alternative to interrupts is polling
Twin sisters on a trip to Disneyland
Polly is highly energetic and vocal, keep asking “Are we there yet?” every 10 minutes
Molly is a daydreamer, busy with her own thoughts, has to be told when they arrive
Basic Computer Architecture
• Dividing CPU’s attention among many tasks
An alternative to interrupts is polling
Disk
Printer
Memory
Screen
Keyboard
Screen
Keyboard
Screen
Keyboard
Disk
Disk
Processor
Plotter
A possible scenario with interrupts
Consider the Java statement:
i = i + 1; // assume i has initial value
of 3
// assume i is global
A possible scenario with interrupts
Consider the Java statement:
i = i + 1;
Equivalent machine instructions could be
1. Copy value of i to CPU register i = 3
2. Add 1 to CPU register gives 4
3. Save value of CPU register i = 4
In program A
. . .
Copy value of i to register i = 3
Add 1 to registergives 4
Save value of register i = 4
. . .
i = i + 1 i = 3
In program B
. . .
Copy value of i to register i = 3
Add 2 to registergives 5
Save value of register i = 5
. . . i = i + 2
i = 3
In program B
. . .
Copy value of i to register i = 3
Add 2 to registergives 5
Save value of register i = 5
. . . i = i + 2
In program A
. . .
Copy value of i to register i = 3
Add 1 to registergives 4
Save value of register i = 4
. . .
i = i + 1
What if we want to run both programs?
i = 3
In program B
. . .
Copy value of i to register i = 4
Add 2 to registergives 6
Save value of register i = 6
. . .
In program A
. . .
Copy value of i to register i = 3
Add 1 to registergives 4
Save value of register i = 4
. . .
Executing them sequentially
i = 3
i = 4
In program B
. . .Copy value of i to register i = 3
Add 2 to registergives 5
Save value of register i = 5
. . .
In program A
. . .
Copy value of i to register i = 3
Add 1 to registergives 4
Save value of register i = 4
. . .
With interrupts
i = 3
In program B
. . .Copy value of i to register i = 3
Add 2 to registergives 5
Save value of register i = 5
. . .
In program A
. . .
Copy value of i to register i = 3
Add 1 to registergives 4
Save value of register i = 4
. . .
Very important question!
Did we get the same result as executing the programs sequentially?
i = 3