UP | HOME

Distributed Computing

Starvation-Free Mutual Exclusion

Udding and Morris Algorithms using Weak Semaphores

Prabhaker Mateti

The Four+ Requirements

  1. R1: Mutex
  2. R2: Deadlock-Free
  3. R3: No Unnec Delay
  4. R4: Eventual Entry
  5. "Std" mutex solution: sem m := 1; ... P(m); CS; V(m); ...
  6. R5: Starvation Free

Udding's Solution

1 P(eu); ne := ne+1; V(eu);
2 P(qu); P(eu);
3  nm := nm+1;
4  ne := ne-1;
5  if ne > 0 --> V(eu)
6  [] ne = 0 --> V(mu)
7  fi;
8 V(qu);
9 P(mu); nm := nm-1;
a Critical Section
b if nm > 0 -->  V(mu)
c [] nm = 0 -->  V(eu)
d fi
   
  1. semaphores: eu := 1, mu := 0, qu := 1;
  2. invariant: 0 ≤ eu + mu ≤ 1
  3. split binary semaphores
  4. initially: eu := ...; mu := ...; qu := ...
  5. idea: inner/outer gates
  6. Initial values of counters:
    ne := 0; nm := 0;

Solution Idea

Idea: Inner/Outer Gates; black-box = critical section; tiny circles = processes; the black circle just finished the CS.

After understanding the idea, disassociate the diagram from the Udding-alg. The gates do not quite correspond to eu mu, and the blue + red processes do not get counted as ne nm.

Deeper Analysis

  1. Consider the following situation. Suppose s == 0. A process P1 is about to do a V(s).
  2. CP := Collection of processes waiting to do P(s) in that scenario
  3. If CP is empty, there is nothing interesting. If CP is non-empty, ...

Deeper Analysis

  1. Is P1 in CP?
  2. When s becomes 1, a process from CP completes the P-operation.
  3. Which process? Any one? FCFS?
  4. What is the time gap between the completion of V(s) and await-testing of s > 0?
  5. Can P1 join CP?     (P1 has code of the form {...; V(s); ...; P(s); ...})

Weak Semaphore Assumption

When s becomes 1, an arbitrary process from CP completes the P-operation. Recall the definitions:

P(s) ≡ ‹ await s > 0 → s := s-1 ›
V(s) ≡ ‹ s := s+1 ›

Let CP be the name we give to the collection of processes waiting to do P(s).

Consider the following situation. Suppose s == 0. A process P1 is about to do a V(s). If CP is empty, there is nothing interesting. If CP is non-empty, ...

When s becomes 1, a process from CP completes the P-operation. Which process? Any one? FCFS?

What is the time gap between the completion of V(s) and testing of s > 0?

Can P1 join CP? (Because P has code of the form {... V(s); ...; P(s); ...}

Is this important in the solution above?

What is the semaphore qu doing?

Purpose of Semaphore qu

Discover it!

Comparison

Comparison

The solutions by Udding and Morris to the starvation-free mutual exclusion problem are reproduced below. Conclude nothing from the code line-up.

Udding's solution              | Morris' solution
1 P(eu); ne := ne+1; V(eu);    | P(em); ne := ne+1; V(em);
2 P(qu); P(eu);                | P(qm);
3  nm := nm+1;                 |  nm := nm+1;             
4  ne := ne-1;                 |  P(em); ne := ne-1;
5  if ne > 0 --> V(eu)         |  if ne > 0 --> V(em);V(qm)
6  [] ne = 0 --> V(mu)         |  [] ne = 0 --> V(em);V(mm)
7  fi;                         |  fi;
8 V(qu);                       |
9 P(mu); nm := nm-1;           | P(mm); nm := nm-1;             
a Critical Section;            |  Critical Section;
b if nm > 0 -->  V(mu)         |  if nm > 0 -->  V(mm) 
c [] nm = 0 -->  V(eu)         |  [] nm = 0 -->  V(qm) 
d fi                           |  fi 

References

This lecture is based on
  • J.M. Morris, A starvation-free solution to the mutual exclusion problem. Information Processing Letters, 8:76--80, 1979. Recommended Reading.
  • J.T. Udding, Absence of individual starvation using weak semaphores, Information Processing Letters, 23:159--162, 1986. Highly Recommended Reading.

References #2

  • Wim Hesselink, Mark IJbema, "Starvation-free mutual exclusion with semaphores", Formal Aspects of Computing, 2011, pp. 1-23. A journal paper based on IJbema's MS. Recommended Reading.
  • Mark IJbema, "Mutual Exclusion Using Weak Semaphores", Master's Thesis [PDF] , 75 pp, Univ of Groningen, The Netherlands, 2011. Explores the Morris and Udding algorithms deeply. Recommended Reading.
  • Stuart A. Friedberg and Gary L. Peterson, "An efficient solution to the mutual exclusion problem using weak semaphores", Information Processing Letters, Volume 25, Issue 5, 1987. Another solution using semaphores. Highly Recommended Reading.

References #3

  • Anderson, James H., Kim, Yong-Jik, Herman, Ted, "Shared-memory mutual exclusion: major research trends since 1986" Distributed Computing, 2003, pp 75--110. Broadens your understanding. Relevant Reading.
  • Alex Aravind, Wim Hesselink, "A queue based mutual exclusion algorithm", Acta Informatica, 73--86, 46, 1, 2009. Not part of this course. Relevant Reading.
  • Edsger W. Dijkstra, "A tutorial on the split binary semaphore", EWD703, http://www.cs.utexas.edu/~EWD/ewd07xx/EWD703.PDF, 1979. Introduced the idea of split binary semaphores. Classic. Turning award winner. Relevant Reading.

Copyright © 2020 pmateti@wright.edu