CEG 7370 | Actors Akka Scala Overview | Slides | Single-Page

Parnas' Solution to the Readers/Writers

m1, m2, m3, r, w  : semaphore := 1
nreaders, nwriters : integer := 0

Reader Process {
  P(m3);
    P(r);
      P(m1);
      nreaders++;
      if (nreaders == 1) then P(w) fi;
      V(m1)
    V(r);
  V(m3);
  ... reading ...;
  P(m1);
  nreaders--;
  if (nreaders == 0) then V(w) fi;
  V(m1);
}

Writer Process {
  P(m2);
  nwriters++;
  if (nwriters == 1) then P(r) fi;
  V(m2);
  P(w);
  ... writing ...;
  V(w);
  P(m2);
  nwriters--;
  if (nwriters == 0) then V(r) fi;
  V(m2)
}
  1. Note that "… reading …" is not immediately preceded by a P operation. But note the P(w).
  2. Make sure you understand the need for m3
  3. Does the above provide "priority" to writers?

1 References

  1. Courtois, Pierre-Jacques, Frans Heymans, and David Lorge Parnas. "Concurrent control with “readers” and “writers”." Communications of the ACM 14.10 (1971): 667-668.
  2. Courtois, Pierre-Jacques, F. Heymans, and David Lorge Parnas. "Comments on “A comparison of two synchronizing concepts by PB Hansen”." Acta Informatica 1.4 (1972): 375-376.

Copyright © 2015 pmateti@wright.edu www.wright.edu/~pmateti 2015-03-13