Lecture Notes for Concurrent Programming

17 June 2003 - Implementing Critical Sections


Outline


A Simple Implementation


Removing Interference


Removing Atomicity


Software Atomicity


Take Turns


Turn-Taking Analysis


Ordering Waiters


Ticketing Global Invariant


Ticketing Properties


Implementing Ticket Ordering


Alternatives to Tickets


The Bakery Algorithm


Bakery Algorithm Properties


Implementing The Bakery Algorithm


Tie-Breaking Again


Critical Section Interfaces


Critical Section Implementations

class two_way_tie_breaker
  : critical_section

  two_way_tie_breaker()
    in[0] = in[1] = false;

  void entry(unsigned me)
    assert (me == 0) or (me == 1)
    assert !in[me]
    const unsigned other = (me + 1) % 2
    in[me] = true ; winner = other
    while (in[other] and winner == other) ;
    
  void exit(unsigned me)
    assert (me == 0) or (me == 1)
    assert in[me]
    in[me] = false

  bool in[2]
  int winner


Points to Remember


This page last modified on 25 June 2003.