FIT2070 Lecture Notes - Lecture 5: Mutual Exclusion, Uniprocessor System, Code Segment
L5 - Concurrency: Mutual Exclusion & Synchronisation
Contexts
● Multiple Applications: process time shared between applications
● Structured Applications: doing modular design
● OS Structure: OS designed as a set of processes or threads
Principles
● Uniprocessor: speed of execution of processes cannot be predicted
● Multiprocessor: interleaving(?) and overlapping
Difficulties
● Race condition: accessing the shared data in the same time could lead to data
inconsistency as processes may change data
○ Prevented by: concurrent processes must be synchronised
OS Concerns
● Protect data and physical resources of each process
● Ensure process and outputs are independent of the processing speed
● Keep track of various processes
● Allocate and de-allocate resources for each active process
Resource Competition
● When processes compete for the use of the same resource
● Control problems faced:
○ Need for mutual exclusion
■ Critical section
● A code segment in a process
● Shared data is accessed/manipulated
■ Ensure that when one process is execution in its critical section, no
other process is allowed in its critical section
○ Deadlock
■ Two (or more) process are waiting forever for the other process to
release the resources
○ Starvation
■ Blocking a process for an undetermined amount of time
Mutual Exclusion
● Condition in which there is set of concurrent processes, only one of which is able to
access a given resource or perform a given function at any time
Flags
● Used when a process is using the shared resource so that others can check that flag
and decide to enter/wait in their critical section
● On (used) or off (not used) - form of semaphore