Lect6 - DS - Synchronization
Lect6 - DS - Synchronization
Lect6 - DS - Synchronization
Introduction
Sharing system resources among multiple
concurrent processes may be:
Cooperative or competitive in nature.
2. A counter register
Keeps track of the oscillations of the quartz crystal.
If value is zero, an interrupt is generated and
reinitialized to the value of constant register.
3. A constant register
Stores a constant value, based on the frequency of
oscillation of the quartz crystal.
Cont…
Each interrupt is known as a clock tick.
Ideal case:
dC/dt =1
Cont…
A clock is nonfaulty if
The maximum drift rate allowable is ρ.
Condition :
1- ρ <= dC/dt <=1 + ρ
slow, perfect and fast clocks
Perfect clock
dC/dt = 1
Fast clock region
dC/dt > 1
Clock
time
Slow clock region
dC/dt < 1
Real time
Cont…
Types of clock synchronization in DS:
1. Synchronization of the computer clocks with
real-time (or external) clocks.
2. Distributed algorithms
Centralized algorithms
Use of time server node for referencing the
correct time.
e32
e24
e13
e23
e12
e22
e31
time
e21
e11
Events
e30 Message
e10 e20 transfer
2. Physical clocks
Using counters
Each process has a counter like C1 and C2
for process P1 and P2, respectively.
Counters
Act as logical clocks.
Initialized to zero.
Increments by 1 on events of the process.
Cont…
C1=3 e03
e12 C2=2
C1=2 e02
C1=1 e01
e11 C2=1
C1=0 C2=0
Process P1 Process P2
Using physical clocks
Each process has a physical clock
associated with it.
Each clock runs at a constant rate (it may
be different for each of these process).
Example:
When Process p1 has ticked 10 times, process
p2 has ticked only 8 times.
Physical clock times if Physical clock times
No corrections were made after corrections (if any)
e06 90 72 77
e05 80 64 69
70 Timestamp =60 56 61 e13
Time e04 60 48
50 40
e03 40 32 e12
e02 30 24
20 16 e11
e01 10 8
0 0
Process P1 Process P2
Total ordering of events
No events can occur at exactly the same
time.
2. No starvation
Cont…
Mutual exclusion:
Given a shared resource accessed by multiple concurrent
processes, at any time only one process should access
the resource.
Can be implemented in single-processor systems, using
semaphores, monitors and similar constructs.
No starvation:
If every process that is granted the resource eventually
releases it, every request must be eventually granted.
Cont…
Approaches:
1. Centralized approach
2. Distributed approach
3. Token passing approach
Centralized approach
One of the processes in the system is elected as
the coordinator.
3) Request 7) Release
6) Reply
5) Release 9) Release
2) Reply 8) Reply
P1 Pc P3
1) Request 4) Request
No starvation:
Due to use of first-come, first-served
scheduling policy.
Cont…
Advantages of algorithm:
Simple to implement
Requires only three messages- a request, a
reply and a release.
Drawbacks:
Coordinator is the single point of failure.
Distributed approach
The decision making for mutual exclusion
is distributed across the entire system.
All processes that want to enter the same
critical section cooperate with each other
before reaching a decision on which process
will enter the critical section next.
Ricart and Agrawala Algorithm
Use of event-ordering scheme to generate a
unique timestamp for each event in the system.
TS=4
TS=6
TS=4 TS=6
P4 P3
Already in the
critical section
Exits critical P4 P3
section
P4 P3
2. Lost token
Process failure
Process receiving token from neighbour always
sends an ACK
Each node maintains current ring configuration
If process fails, dynamic reconfiguration of ring is
carried out.
When process turns alive, it simply informs to
others.
Lost Token
To regenerate lost token – one process in the
ring acts as a Monitor process.
Monitor periodically circulates “who has the token
message”
Process containing token inserts its id in the
special field
If no id found implies token lost.
Problems:
Monitor process may itself fail
Who has the token message may be lost