synchronization
Course 5: Review
Scheduler - Selects from among the processes in memory that are ready
switching context
Criteria:
CPU utilization
Throughput
Turnaround time
Waiting time
Response time
6.2
Course 5: Review
Scheduling Algorithms:
FCFS batch
SJF TS
Round Robin
Multilevel
Priority
6.3
6.4
6.5
Concurrency background
Computations can take advantage of multiple processing
6.6
Concurrency background
Even on systems with a single processing unit we may give the
Terminology:
6.7
Concurrent programs
A program which at runtime gives rise to a process
6.8
Concurrent programs
6.9
Concurrent programs
6.10
Race conditions
If processes/threads are completely independent, concurrency is easy
Much more often threads interfere with each other, for example by
testing
6.11
Atomic instructions
An instruction is atomic if its execution cannot be interleaved with other
x := x + 1
is on many systems executed as:
temp := x -- LOAD R0, x
temp := temp + 1 -- ADD R0, 1
6.12
Atomic instructions
To reflect the different assumption on atomicity, the concurrent
program is restated:
6.13
Interleaving semantics
6.14
6.15
Interleaving semantics
The interleaving semantics provides a good model for concurrent
6.16
Transition systems
A formal model that allows us to express concurrent computation
such as:
P22 (the program pointer of P2 points to 2)
x = 6 (the value of variable x is 6)
There is a transition between two states if one state can be
6.17
6.18
6.19
Synchronization
In order to solve the problem of data races, processes have to
6.20
problem
6.21
6.22
starts eating; after having eaten, the philosopher puts down the left fork,
then the right one
The philosophers can deadlock
6.23
conditions
6.24
and then starts eating; after having eaten, the philosopher puts them
both back down
A philosopher could starve
6.25
Starvation
Even if no deadlock occurs, it may still happen that some processes
6.26
Mutual exclusion
Race conditions can corrupt the result of a concurrent computation if
6.27
Mutual exclusion
We assume to have n processes of the following form:
6.28
Mutual exclusion
Further important conditions:
non-critical section
The memory locations accessed by the protocols may not
6.29
Locks
Synchronization mechanisms based on the ideas of entry and exit-
6.30
Busy waiting
We will use the following statement in pseudo code
await b
--which is equivalent to
6.31
Solution attempt 1
First idea: use two variables enter1 and enter2; if enter is
6.32
Solution attempt 1
The solution attempt fails to ensure mutual exclusion
The two processes can end up in their critical sections at
6.33
Solution attempt 2
When analyzing the failure, we see that we set the
6.34
Solution attempt 2
When analyzing the failure, we see that we set the
6.35
Solution attempt 2
The solution provides mutual exclusion
However, the processes can deadlock:
6.36
Solution attempt 3
Third idea: let's try something new, namely a single
variable turn that has value i if it's Pi's turn to enter the
critical section
6.37
Solution attempt 3
Solution attempt III looks good to us, let's try to prove it
correct
Draw the related transition system; states are labelled
with triples (i, j, k): program pointer values P1i and P2j,
and value of the variable turn = k.
6.38
Solution attempt 3
Solution attempt III satisfies mutual exclusion - there are
6.39
End of Course 6