Lecture 16

Review -- Passing the Baton (on board at start)

   << S1; >>                << await (B) S2; >>

   P(e);                    P(e);
   S1;                      if (!B)
   SIGNAL;                     { cnt++; V(e); P(delay); }
                            S2;
                            SIGNAL;

   the SIGNAL code does a V on exactly ONE semaphore
   split binary semaphores and the use of P and V above ensures mutual exclusion between each P and V

   any questions?  be sure to learn this; you can count on its being on the midterm!


Implementations of Processes and Semaphores -- Chapter 6

   you have seen (or are seeing) many of these ideas in your OS course,
      at least for a single processor
   I am going to briefly review that material and then focus on multiprocessor
      implementation issues


   SR             your code
                  ----
                  RTS

   Pthreads       your code
                  -----
                  Pthreads library

   both SR's RTS and the Pthreads library interact with Unix


Single Processor Kernel -- Section 6.1

   kernel structure -- Figure 6.1

   data structures
      descriptors -- for processes, semaphores, etc.
      lists -- empty, ready processes, blocked processes, etc.

   primitives -- "system calls" that appear to be atomic
      fork -- used for co and process declarations (in SR)
      join -- used for oc
      quit -- end of a process or an arm of co
      P and V

   outline of a single processor kernel -- Figure 6.2

   adding semaphores to the kernel -- Figure 6.5 (from Section 6.3)


Multiprocessor Kernel -- Section 6.2

   idea:  kernel code can be executed by any processor and kernel data is shared

   two main changes:
      need to use locks to provide atomic access to kernel data
      need to modify dispatcher to make use of all processors

   outline of multiprocessor kernel -- Figure 6.4

      note use of locks around the statements that access shared data

      Multiprocessor Locking Principle -- equation (6.1)
         make critical sections short; use separate locks for each data structure
         need to be careful to avoid deadlock
         example:  MultiSR (the SR implementation for multiprocessors) has 28 locks
                   these are organized into 11 classes (levels)
                   acquire locks in class order to avoid circular waiting

   idle processors -- want to get them busy when there are threads to execute

      strategies:  search and assign (sender initiated)
                   use separate scheduling processor
                   have idle processors execute an "idle process" (receiver initiated)

      the latter strategy (idle process) is the most efficient -- what else does
         an idle processor have to do?

      idle process code -- Figure 6.3
         go over the code; it is kind of tricky
         notice the "Test and Test and Set" (double check) idea; why do you need to recheck?


Midterm Preparation 

   coverage:  Chapters 1-4 and Section 11.2

   notes:  you may bring up to 4 pages of notes that you have prepared
           these may be handwritten or typed, but no copies of stuff
           I believe that the act of preparing the notes is a great way
              to review for the exam

   format:  there will be 5 questions
            you are to write your answers on the exam sheets
               (hint:  I'll provide enough space for a correct answer)

   hand out copies of last year's exam; this year's will be similar

   go over the exam using transparencies
      serves as a brief review of major topics