Docsity

Synchronization - Distributed Operating Systems - Lecture Slides, Slides of Operating Systems

Partial preview of the text

Download Synchronization - Distributed Operating Systems - Lecture Slides and more Slides Operating Systems in PDF only on Docsity!

Synchronization

  • Part I Clock Synchronization & Logical clocks
  • Part II Mutual Exclusion
  • Part III Election Algorithms
  • Part IV Transactions

Motivation

  • Synchronization is important if we want to
    • control access to a single, shared resource
    • agree on the ordering of events
  • Synchronization in Distributed Systems is much more difficult than in uniprocessor systems We will study:
  1. Synchronization based on “Actual Time”.
  2. Synchronization based on “Relative Time”.
  3. Synchronization based on Co-ordination (with Election Algorithms).
  4. Distributed Mutual Exclusion.
  5. Distributed Transactions.

Lack of Global Time – Example

When each machine has its own clock, an event that occurred after another event may nevertheless be assigned an earlier time.

A Note on Real Time

  • Universal Coordinated Time (UTC):

basis of all modern civil timekeeping

  • Radio stations can broadcast UTC for

receivers to collect it

  • WWV SW radio station in Colorado

Cristian’s Algorithm – External Synch

  • External source S
  • Denote clock value at process X by C(X)
  • Periodically, a process P:
    1. send message to S, requesting time
    2. Receive message from S, containing time C(S) 3. Adjust C at P, should we set C(P) = C(S)?
  • Reply takes time
  • When P adjusts C(P) to C(S), C(S) > C(P)

Cristian’s Algorithm – External Synch

  • How to estimate machine A’s time offset relative to B? B A T 2 T 1 T 3 T 4

Berkeley Algorithm – Internal Synch

  • Internal: synchronize without access to an external resource |C i (t) – C j (t)| < D Periodically, S: send C(S) to each client P P: calculate  P

= C(P) – C(S)

send  P to S S: receive all  P ’s compute an average  send - P to client P P: apply - P to C(P)

The Berkeley Algorithm

a) The time daemon asks all the other machines for their clock values b) The machines answer c) The time daemon tells everyone how to adjust their clock

  • Propagation time?
  • Time server fails?

Event Ordering in Centralized

Systems

  • A process makes a kernel call to get the time
  • Process which tries to get the time later will

always get a higher (or equal) time value

 no ambiguity in the order of events and their time

Logical Clocks

  • For many DS algorithms, associating an

event to an absolute real time is not

essential, we only need to know an

unambiguous order of events

  • Lamport's timestamps
  • Vector timestamps

Example: Why Order Matters?

  • Replicated accounts in New York(NY) and San Francisco(SF)
  • Two updates occur at the same time
    • Current balance: $1,
    • Update1: Add $100 at SF; Update2: Add interest of 1% at NY
    • Whoops, inconsistent states!

Lamport Algorithm

  • Clock synchronization does not have to be exact
    • Synchronization not needed if there is no interaction between machines
    • Synchronization only needed when machines communicate
    • i.e. must only agree on ordering of interacting events

Concurrent Events

  • Given two events e & e’:
  • If neither e < e’ nor e’< e, then e || e’ P 1 P 2 P 3 Real Time a b c f d e m 1 m 2

Lamport Logical Clocks

  • Substitute synchronized clocks with a global

ordering of events

  • e i < e j  LC(e i ) < LC(e j

– LC

i is a local clock: contains increasing values

  • each process i has own LC i
  • Increment LC i on each event occurrence
  • within same process i, if e j occurs before e k
  • LC i (e j ) < LC i (e k )
  • If e s is a send event and e r receives that send, then
  • LC i (e s ) < LC j (e r )