UNIX/Linux & C Programming:
Chapter n: The Token Ring



Coverage: [USP] Chapter 7


Introduction to the token ring (of processes)

  • nodes = processes
  • links = pipes
  • each process is a filter
    • reads from standard input
    • writes to standard output
  • simple
  • inexpensive
  • unidirectional communication: clockwise; each entity has a connection for input and output
  • latency increases as #nodes increase
  • bandwidth is independent of ring size (#nodes)


Base case: token ring of one process

  • process communicates to itself through a pipe
  • notice data written using printf is buffered


Now n=2


(regenerated with minor modifications from [USP] Fig. 7.7, p. 232)

  • extending a ring of one process to one of two processes is fairly straightforward
  • now we need two pipes
  • parent's standard input read from standard output of child
  • child's standard input read from standard output of parent


Extending the ring to an arbitrary number of processes

  • easily extended
  • #pipes necessary = #processes
  • still only 1 array of size 2 necessary for pipe file descriptors
  • resembles process chain (i.e., each process only forks once)
  • in-class exercise: coding infrastructure necessary for token ring with an arbitrary number of processes
    • take #processes n as a command-line argument
    • done in <65 loc, including all of the error checking code


Ring exploration

  • [USP] §7.3
  • in-lab exercise


Ring of processes communicating through (unamed) pipes vs.
Ring of threads communicating through channels

Key: ▢ = process, { or } = thread, → = data, and ~ = pipe or channel.

Ring of processes communicating through (unamed) pipes (C model)           Rings of threads communicating through channels (Go model)
         


Demo of Robbins and Robbins' process ring simulator


The Fibonacci series on the ring

  • [USP] §7.4
  • in-class exercise
  • we were able to compute up to and including the 78th Fibonacci number, using 77 processes; using unsigned long long and the %llu conversion specifier


References

    [USP] K.A. Robbins and S. Robbins. UNIX Systems Programming: Concurrency, Communication, and Threads. Prentice Hall, Upper Saddle River, NJ, Second edition, 2003.

Return Home