Lecture 4&5-Concurrent vs sequential programming Flashcards
What is the Kernel vs User Mode?
What is a Heavyweight processes?
A process is an operating system abstraction to represent what is needed to run a program.
It consists of:
- Sequential Program Execution Stream (includes state of CPU registers)
- Protected resources: memory state, I/O state
No concurrency inside heavyweight processes!
What is PCB, address space and context switch?
The current state of the process is held in the PCB (Process Control Block)
To multiplex several processes we need to give CPU time using efficient scheduling policies.
- preemptive: SRT, RR
- non-preemptive: FCFS, SJF
Controlled access to non-CPU resources, e.g. memory, I/O.
What are Threads?
A thread is an independent sequence of execution within a program
What is the Concept of Thread?
A thread is similar to a process
- Both have a single sequential flow of control with a start and end
- At any time a thread has a single point of execution
- A thread has its execution stack & program counter
- Sometimes a thread is called a lightweight process
However, a thread differs from a process
- A thread cannot exist on its own. It exists within a process
- Usually created and/or controlled by a process
- Threads can share a process’s resources, including memory and open files
What is Sequential Programming?
Traditional activity of constructing a program containing one process using a (sequential) computer language
The program is supposed to execute on a single processor architecture
What is Single Processor Architecture?
A CPU is linked to RAM and I/O devices by buses
Both program instructions and data are stored in RAM
The CPU repeatedly executes the cycle of
- Fetching, decoding and executing the next instruction
- Referenced by the current value of program counter (PC)
Can at most be executing one instruction at any time
What is Total Ordering?
What is meant by “P must precede Q”?
Q can only begin after P finishes
The execution sequence at the program level
P; Q; R;
implies the execution sequence at the system level
p, q1, q2, q3, r1, r2, r3
Single threaded computation, no overlap in the execution of the
statements — Total Ordering
What is System Level Execution?
Each statement may be compiled into several machine instructions.
Executing a Sequential Program?
The execution sequence is the sequence of values of PC
Deterministic: only one possible sequence of execution
A sequential program gives the system strict instructions on the order of executing the statements in the program.
What is the Nature of Sequential Programming?
Total ordering
Deterministic: same input same output
Sequential programming ⇔ Finding a strict sequence of steps to achieve the desired end
This mode does not apply for many practical problems
What is Parallel Computation and Partial Ordering?
The operations carried out by Bingxing’s 607279 soldiers were NOT in a total order.
They were carried out in parallel
Each individual soldier did his operations in sequence
The operations in the whole computation can be viewed as in a partial order
What is Concurrent Programming?
The activity of constructing a program containing multiple
processes/threads that execute in parallel
These processes may run on
A multi-processor system
A single processor system
Needs language support, e.g., Java Thread and Socket
Why Concurrent Programming?
Improve efficiency in program execution using multi-CPU hardware
(Chinese General Problem)
Improve CPU utilisation via multi-tasking on a uni-CPU system
(operating systems)
Some applications are inherently non-deterministic and concurrent,
e.g., embedded traffic lights controller
The order of program operations is determined by external events,
e.g., a sensor is triggered by a coming vehicle
Impossible to predict the order of these events, e.g., a car from the north comes first, and then one from the east, and so on
How to Represent Concurrent Program?
Use COBEGIN/COEND to bracket the processes
The program ends only if all processes in COBEGIN/COEND
terminate
The statements in COBEGIN/COEND may overlap in the
execution, but we cannot say they must do so