Bakery%20Algorithm%20-%20Proof - PowerPoint PPT Presentation

About This Presentation
Title:

Bakery%20Algorithm%20-%20Proof

Description:

We conclude that mutual exclusion is satisfied. OS Spring'03. Lemma 3 Proof ... We conclude that Bakery algorithm satisfies Progress. OS Spring'03. Lemma 4 Proof ... – PowerPoint PPT presentation

Number of Views:1645
Avg rating:3.0/5.0
Slides: 15
Provided by: GregoryC9
Category:

less

Transcript and Presenter's Notes

Title: Bakery%20Algorithm%20-%20Proof


1
Bakery Algorithm - Proof
  • Operating Systems
  • Spring 2003

2
Bakery algorithm for n processes
R
T
D
T-D
C
E
3
Structure of the algorithm
  • R code prior to using Bakery algorithm
  • T creating of a ticket and awaiting for
    permission to enter critical section
  • D creation of a number (first part of a ticket)
  • T-D awaiting for the permission to enter
    critical section
  • C critical section itself
  • E code executed upon exit from critical section

4
Basic Lemma
Lemma 1
5
Lemma 1 - proof
  • Denote s time point where lemmas conditions
    hold
  • At time s, is in C (critical section)
  • numberi has been selected and still exists
  • numberj has been selected and still exists
  • Exist time point t1lts, where performs a
    check (choosingj0) and passes it
  • Exists time point t2, t1ltt2lts, where
    performs a check
  • (numberj!0) and (numberi,i)lt(numberj,j)

6
Lemma 1 proof (cont)
  • Since at time t1 exists (choosingj0) one of
    the following has to be true
  • CASE A numberj was chosen after time t1 and
    before time s
  • CASE B numberj was chosen before t1

7
Lemma 1 proof CASE A
  • Since at time t1 already checks for
    permission to enter critical section, computation
    of numberi was computed before that and
    persists until s
  • Thus, at the time starts to compute its
    numberj, it has to take into account of max
    value of numberi. So it creates a value which
    is greater then numberi at least by 1, and it
    persists until time s
  • That is (numberi,i)lt(numberj,j) at time s

8
Lemma 1 proof CASE B
  • Both numberi and numberj were computed before
    t1, thus also before time t2 and persisted
    until s
  • At time t2 performed check (numberj!0)
    (numberj,j)lt(numberi,i), which failed,
    since is in C at time s
  • numberj was chosen before t2 and persisted,
    thus first part of the check could not fail, also
    i and j are different, so
  • (numberi,i)lt(numberj,j) at time s

9
Lemmata 2,3,4
  • Lemma 2 mutual exclusion
  • Bakery Algorithm satisfies mutual exclusion
    property
  • Lemma 3 progress
  • Bakery Algorithm guarantees progress
  • Lemma 4 fairness
  • Bakery Algorithm guarantees lockout-freedom

10
Lemma 2 Proof
  • Assume in contradiction that there are two
    different processes that have entered critical
    section
  • Then conditions of Lemma 1 are true for both
    processes simmetrically that is
    (numberi,i)lt(numberj,j) and
    (numberj,j)lt(numberi,i) contradiction
  • We conclude that mutual exclusion is satisfied

11
Lemma 3 Proof
  • Suppose progress is not guaranteed
  • Then eventually a point is reached after which
    all processes are in T or R
  • By the code, all the processes in T eventually
    complete D and reach T-D
  • Then the process with the lowest (number,ID) pair
    is not blocked from reaching C, that is enters
    critical section
  • We conclude that Bakery algorithm satisfies
    Progress

12
Lemma 4 Proof
  • Consider a particular process in T and
    suppose it never reaches C
  • The process eventually completes D and reaches
    T-D
  • After that any new process that enters D
    perceives numberi and chooses a higher number
  • Thus, since does not reach C, none of these
    new processes reach C either
  • But by Lemma 3 there must be continuing progress,
    that is infinitely many entries to C
  • Contradiction blocks the entry to C

13
Remark on Fairness
  • A process that obtained a ticket (numberk,k)
    will wait at most for (n-1) turns, when other
    processes will enter the critical section
  • For example if all the processes obtained their
    tickets at the same time they will look like
    (q,1),(q,2)(q,n)
  • In which case process will wait for processes
  • to complete the critical section

14
Bibliography
  • Nancy Ann Lynch, Distributed Algorithms, JMC
    243.9 LY53
  • Leslie Lamport
  • A new solution of Dijkstras concurrent
    programming problem
  • Communications of the ACM
  • 17(8)453-455, 1974
Write a Comment
User Comments (0)
About PowerShow.com