Chapter 7 Process Synchronization

Document Sample
Chapter 7 Process Synchronization Powered By Docstoc
					      Chapter 7:
Process Synchronization




                          1
                    Contents
•   Background
•   The Critical-Section Problem
•   Synchronization Hardware
•   Semaphores
•   Classical Problems of Synchronization
•   Monitors
•   Java Synchronization
•   Synchronization in Solaris 2
•   Synchronization in Windows NT
                                            2
                                           § 7.1
              Background
• Concurrent access to shared data may result
  in data inconsistency.
• Maintaining data consistency requires
  mechanisms to ensure the orderly execution
  of cooperating processes.
• Shared-memory solution to bounded-buffer
  problem (Chapter 4) has a race condition on
  the class data count

                                                   3
               Bounded Buffer
Shared data

#define BUFFER_SIZE 10
typedef struct {
   . . .
} item;
item buffer[BUFFER_SIZE];
int in = 0;
int out = 0;
int counter = 0;



                                4
           Producer process
item nextProduced;

while (1) {
    while (counter == BUFFER_SIZE)
            ; /* do nothing */
    buffer[in] = nextProduced;
    in = (in + 1) % BUFFER_SIZE;
    counter++;
}




                                     5
           Consumer process
item nextConsumed;

  while (1) {
      while (counter == 0)
            ; /* do nothing */
      nextConsumed = buffer[out];
      out = (out + 1) % BUFFER_SIZE;
      counter--;
  }


                                       6
               Bounded Buffer
• The statements

  counter++;
  counter--;

  must be performed atomically.

• Atomic operation means an operation that
  completes in its entirety without interruption.

                                                    7
           In machine language
• The concurrent        • count++
  execution of the           register1 = count;
  statements count++         register1= register1 + 1;
  and count-- is             count = register1
  equivalent to a       • count--
  sequential execution       register2 = count;
  where the lower-level      register2= register2 – 1;
  statements are             count = register2
  interleaved in some
  arbitrary order.
                                                         8
              Interleaving
• If both the producer and consumer attempt
  to update the buffer concurrently, the
  assembly language statements may get
  interleaved.

• Interleaving depends upon how the
  producer and consumer processes are
  scheduled.

                                              9
                  Race Condition
T0: producer execute rigister1 := count          {register1=5}
T1: producer execute rigister1 := rigister1 +1   {register1=6}
T2: consumer execute rigister2 := count          {register2=5} Should
                                                                be 5.
T3: consumer execute rigister2 := rigister2 –1   {register2=4}
                                                               Error!
T4: producer execute count := rigister1          {count =6}
T5: consumer execute count := rigister2          {count =4}




                                                                    10
             Race Condition
• Race condition: The situation where several
  processes access – and manipulate shared data
  concurrently. The final value of the shared data
  depends upon which process finishes last.
• To guard against the race condition, we need to
  ensure that only one thread at a time can be
  manipulating the variable count. To make such a
  guarantee, we require some form of
  synchronization of the processes.

                                                     11
       Critical-Section Problem                     § 7.2

• n processes all competing to use some shared data
• Each process has a code segment, called critical
  section, in which the in which the thread may be
  changing common variables, updating a table,
  writing a file, and so on.
• Problem – ensure that when one process is
  executing in its critical section, no other process is
  allowed to execute in its critical section... mutually
  exclusive.
• The critical-section problem is how to choose a
  protocol that the threads can use to cooperate.

                                                            12
       Critical-Section Problem                   § 7.2

• ) When one process is executing called a critical
( Each thread has a segment of code,in its critical
     section, which the thread is to be allowed
   section, in no other process may be changing to
   common variables, updating a table, writing a file,
     execute in its critical section, this is called
   and so on.
     _________.
• When global datais(B) common its critical(C)
     (A) one thread executing in method section,
   nomutually exclusive (D) constant accessing (E)
       other thread is to be allowed to execute in its
     value assertion
   critical section…mutually exclusive.
• Answer: C
   The critical-section problem is how to choose a
   protocol that the threads can use to cooperate.

                                                          13
        Critical-Section Problem
1. Mutual Exclusion. If process Pi is executing in its critical
  section, then no other processes can be executing in their
  critical sections.
2. Progress. If no process is executing in its critical section
  and there exist some processes that wish to enter their
  critical section, then the selection of the processes that will
  enter the critical section next cannot be postponed
  indefinitely.
3. Bounded Waiting. A bound must exist on the number of
  times that other processes are allowed to enter their critical
  sections after a process has made a request to enter its
  critical section and before that request is granted.



                                                                    14
        Critical-Section Problem
1. Mutual Exclusion. If process Pi is executing in its critical
Short Answer Question: can be executing in their
  section, then no other processes
   A solution to
  critical sections. the critical-section problem must
satisfy three requirements: mutual critical section
2. Progress. If no process is executing in itsexclusive,
  and there              processes that          to enter their
progress, exist some the selection ofwishprocesses that will
              and bounded waiting. Please explain
  critical section, then                    the
  enter the critical these requirements.
the meaning ofsection next cannot be postponed
  indefinitely.
3. Bounded Waiting. A bound must exist on the number of
  times that other processes are allowed to enter their critical
  sections after a process has made a request to enter its
  critical section and before that request is granted.
     Assume that each process executes at a nonzero speed
     No assumption concerning relative speed of the n processes.

                                                                    15
        Critical-Section Problem
1. Mutual Exclusion. If process Pi is executing in its critical
Multiple Choice Question: can be executing in their
  section, then no other processes
    ) Which of
( critical sections.the following is not one of the
       requirements for a solution of critical-section
2. Progress. If no process is executing in its critical section
  and there exist some processes that wish to enter their
       problem?
  critical section, then the selection of the processes that will
       (A) critical section loopless be postponed
  enter theprogress (B)next cannot (C) mutual
  indefinitely.
       exclusive (D) bounded waiting
3. Bounded Waiting. A bound must exist on the number of
  times that other processes are allowed to enter their critical
  sections after a process has made a request to enter its
  critical section and before that request is granted.
     Assume that each process executes at a nonzero speed
     No assumption concerning relative speed of the n processes.

                                                                    16
      Critical-Section Problem
• We can make no assumption concerning the
  relative speed of the n threads.
• The solutions should not rely on any assumptions
  concerning the hardware instructions.
• However, the basic machine-language instructions
  (the primitive instructions such as load, store,
  and test) are executed atomically.




                                                     17
      Critical-Section Problem
• We can make no assumption concerning the
True-False Question:
( relative speed of the n threads. problems, we
   ) When solving critical section
• The solutions should notassumption concerning
     should make proper rely on any assumptions
     the relative hardware instructions.
  concerning thespeed of the threads.
• However, the basic machine-language instructions
    Answer: ×
  (the primitive instructions such as load, store,
  and test) are executed atomically.




                                                     18
         Two-Process Solutions
• Only 2 processes, P0 and P1
• General structure of process Pi
       do {
               entry section
                   critical section
               exit section
                   reminder section
       } while (1);
• Use Pj to denote the other process. (j == 1 – i)
• Processes may share some common variables to synchronize
  their actions.

                                                             19
                      Algorithm 1
• Shared variables:
  int turn;
  initially turn = 0
  turn == i  Pi can enter its critical section
• Process Pi
      do {
          while (turn != i) ;
               critical section
          turn = j;
               reminder section
      } while (1);
• Satisfies mutual exclusion, but not progress

                                                  20
                  Algorithm 1
• Ensures that only one process at a time can be in its
  critical section.
• However, does not satisfy the progress
  requirement, since it requires strict alternation of
  processes in the execution of their critical section.




                                                          21
                       Algorithm 2
• Shared variables
   – boolean flag[2];
     initially flag [0] = flag [1] = false.
   – flag [i] = true  Pi ready to enter its critical section
• Process Pi
       do {
                 flag[i] := true;
                 while (flag[j]);
                      critical section

                 flag [i] = false;

                      remainder section
        } while (1);
• Satisfies mutual exclusion, but not progress requirement.
                                                                22
                       Algorithm 2
• Shared variables
Short Answer Question:
   – boolean flag[2];
      initially flag [0] = flag [1] = false. the right for
          Examine the algorithm on
   – flag [i] = true  Pi ready to enter its critical section
    solving
• Process Pi two-tasks critical-section problem.
    What this algorithm has achieved and what
        do {
                  flag[i] := true;
    kind of problem this algorithm is encountered,
                  while (flag[j]);
    if any ?
                      critical section

                 flag [i] = false;

                      remainder section
        } while (1);
• Satisfies mutual exclusion, but not progress requirement.
                                                                23
                 Algorithm 2
• The mutual-exclusion requirement is satisfied.
• Unfortunately, the progress requirement is still not
  met.
• Consider the following execution sequence:
      T0: P0 sets flag[0] = true
      T1: P1 sets flag[1] = true
  Now P0 and P1 are looping forever in their
  respective while statements.


                                                         24
                       Algorithm 3
• Combined shared variables of algorithms 1 and 2.
• Process Pi
         do {
                 flag [i]:= true;
                 turn = j;
                 while (flag [j] and turn = j) ;
                     critical section
                 flag [i] = false;
                     remainder section
       } while (1);
• Meets all three requirements; solves the critical-section problem for
  two processes.


                                                                          25
                 Algorithm 3
• Correct solution to the critical-section problem.
  (how to prove it? look at the textbook.)
• If both processes try to enter at the same time,
  turn is set to both i and j at roughly the same
  time.
• Only one of these assignments lasts; the other will
  occur, but will be overwritten immediately.
• The eventual value of turn decides which of the
  two processes is allowed to enter its critical
  section first.
                                                        26
              Bakery Algorithm
Critical section for n processes

  • Before entering its critical section, process
    receives a number. Holder of the smallest
    number enters the critical section.
  • If processes Pi and Pj receive the same
    number, if i < j, then Pi is served first; else Pj
    is served first.
  • The numbering scheme always generates
    numbers in increasing order of enumeration;
    i.e., 1,2,3,3,3,3,4,5...
                                                         27
              Bakery Algorithm
• Notation : lexicographical order (ticket #, process
  id #)
   – (a,b) < (c,d) if a < c or if a = c and b < d
   – max (a0,…, an-1) is a number, k, such that k  ai for i -
     0,
     …, n – 1
• Shared data
         boolean choosing[n];
         int number[n];
  Data structures are initialized to false and 0
  respectively
                                                                 28
            Bakery Algorithm
do {
   choosing[i] = true;
   number[i] = max(number[0], number[1], …, number [n–1])+1;
   choosing[i] = false;
   for (j = 0; j < n; j++) {
             while (choosing[j]) ;
             while ((number[j] != 0) &&
                      ((number[j],j) < (number[i],i))) ;
   }
     critical section
   number[i] = 0;
     remainder section
} while (1);

                                                          29
    Synchronization Hardware               § 7.3
• Hardware instructions can be used
  effectively in solving critical-section
  problem.
• It allows as either to test and modify the
  content of a word, or to swap the contents
  of two words, atomically --- as one
  uninterruptible unit.



                                                   30
      Test-and-Set Instruction
• Test and modify the content of a word atomically.

      boolean TestAndSet(boolean &target) {
           boolean rv = target;
           target = true;
           return rv;
      }


                                                      31
       Test-and-Set Instruction
True-False Question: content of a word atomically.
 • Test and modify the
( ) The value of the lock returned by the
    TestAndSet instruction is the value after the
       boolean TestAndSet(boolean &target) {
    instruction is applied onto the target.
             boolean rv = target;
 Answer: X tqrget = true;
             return rv;
       }


                                                     32
Mutual Exclusion with Test-and-Set
• Shared data:
       boolean lock = false;

• Process Pi
       do {
                 while (TestAndSet(lock));
                    critical section
                 lock = false;
                    remainder section
       }



                                             33
Mutual Exclusion with Test-and-Set
Multiple Choices Question:
• Shared data:
       boolean lock = false;
( ) When calling a test-and-set instruction, a
• Process Pi must be provided as its parameter.
     ______
       do {
     (a) semaphore (b) integer (c) constant (d)
               while (TestAndSet(lock)) ;
     lock         critical section
 Answer: d lock = false;
                  remainder section
      }




                                                  34
Mutual Exclusion with Test-and-Set
                  Question:
True-False lock = false;
• Shared data:
          boolean
   ) When the value returned by the test-and-set
( Process P
•          i
          do {
                           is false, it ;
      instruction (TestAndSet(lock)) means that the locking
                   while
      is not successful.
                      critical section
                   lock = false;
                remainder section
       }

 Answer: x




                                                              35
    Synchronization Hardware
• Atomically swap two variables.

    void Swap(boolean &a, boolean &b) {
        boolean temp = a;
        a = b;
        b = temp;
    }


                                          36
     Mutual Exclusion with Swap
• Shared data (initialized to false):
            boolean lock;
            boolean waiting[n];

• Process Pi
            do {
              key = true;
              while (key == true)
                 Swap(lock,key);
                 critical section
              lock = false;
                 remainder section
            }                           37
    Mutual Exclusion with Swap
• Shared data (initialized to false):
          boolean Question:
Multiple Choices lock;
          boolean the key used
( ) The value of waiting[n]; to switch with the
     lock must be set to ______ before calling the
• Process Pi method.
     swap
          do {
     (a) constant (b) false (c) true (d) integer
  Answer: c  key = true;
             while (key == true)
               Swap(lock,key);
               critical section
             lock = false;
               remainder section
         }                                           38
                  Semaphore                         § 7.4

• Previous solutions (§7.3) are not easy to generalize
  to more complex problems.
• Semaphores can be implemented as synchronization
                           These waiting.
  tool that does not require busyare classical definition
• A semaphore S is an integerPvariable that can only
                              of and V, they require
                                  (atomic) operations:
  be accessed via two indivisible busy waiting.
  P and V.

       P(S) {                        V(S) {
          while S  0                  S++;
            ; // no-op;              }
          S--;
       }                                                    39
                  Semaphore                        § 7.4

• Previous solutions (§7.3) are not easy to generalize
  to more complex problems.
• Semaphores can be implemented as synchronization
  tool that does not require busy waiting.
            New definition has changed
• A semaphore S is an integer variable that can only
               to wait and signal.
  be accessed via two indivisible (atomic) operations:
  P and V.

       P(S) {                       V(S) {
          while S  0                 S++;
            ; // no-op;             }
          S--;
       }                                                   40
                  Semaphore                        § 7.4

• Previous solutions (§7.3) are not easy to generalize
  to more complex problems.
• Semaphores can be implemented as synchronization
  tool that does not require busy waiting.
            New definition has changed
• A semaphore S is an integer variable that can only
               to wait and signal.
  be accessed via two indivisible (atomic) operations:
  P and V.

       wait(S) {                    signal(S) {
          while S  0                 S++;
            ; // no-op;             }
          S--;
       }                                                   41
 Solving critical-section problem
                                             § 7.4.1
• Shared data:
    semaphore mutex; //initially mutex = 1

  Process Pi:
  do {
         wait(mutex);
           critical section
      signal(mutex);
        remainder section
  } while (1);




                                                   42
  Solving Synchronization problems
• P1 with statement S1, P2 with statement S2 and S2 can be
  executed only after S1 has completed.
• Shared data:
    semaphore mutex; //initially mutex = 1
• insert the statements
       S1;
       signal(synch);
  in process P1, and the statements
       wait(synch);
       S2;
  in process P2
                                                             43
  Semaphore Eliminating Busy-
           Waiting           § 7.4.2
• The main disadvantage of previous solutions: they
  all require busy waiting…a problem in single
  CPU, multiprogramming system.
• Busy waiting wastes CPU cycles that some other
  process might be able to use productively. This
  type of semaphore is also called a spinlock.
 • Spinlocks are useful in multiprocessor systems. The
   advantage of a spinlock is that no context switch is required
   when a process must wait on a lock (context switch
   may take considerable time).
 • Spinlocks are useful when locks are expected to be held for
                                                                   44
   short times.
  Semaphore Eliminating Busy-
           Waiting
• The main disadvantage of previous solutions: they
  all require busy waiting…a problem in single
  CPU, multiprogramming system.
• Busy waiting wastes CPU cycles that some other
  process might be able to use productively. This
  type of semaphore is also called a spinlock.
• To overcome the need for busy waiting, the
  definition of wait and signal are modified.


                                                      45
  Semaphore Eliminating Busy-
           Waiting
• The main disadvantage
Short Answer Question: of previous solutions: they
    Although spinlocks waist CPU time with
  all require busy waiting…a problem in singlebusy
    waiting, they are still system.
  CPU, multiprogramminguseful in some systems.
    What are the advantage of spinlocks and in
• Busy waiting wastes CPU cycles that some other
    which situation they are considered useful?
  process might be able to use productively. This
  type of semaphore is also called a spinlock.
• To overcome the need for busy waiting, the
  definition of wait and signal are modified...


                                                     46
   Semaphore Eliminating Busy-
            Waiting
• Rather than busy waiting, the process can block itself.
• The block operation places a process into a waiting
  queue associated with the semaphore, and the state of
  the process is switched to the waiting state.
• A process that is blocked, waiting on S, should be
  restarted when some other process execute a signal
  operation.
• When the process is restarted by the wakeup
  operation, the process is changed from the waiting
  state to the ready state. The process is then placed in
  the ready gueue.
                                                            47
   Semaphore Eliminating Busy-
            Waiting
• Define a semaphore as a record
       typedef struct {
          int value;
          struct process *L;
       } semaphore;

• Assume two simple operations:
   –block suspends the process that invokes it.
   –wakeup(P) resumes the execution of a blocked process P.
• These two operations are provided by the OS as basic
  system calls.

                                                              48
Semaphore Eliminating Busy-
         Waiting
• Semaphore operations now defined as
          void wait (semaphore S) {
               S.value--;
               if (S.value < 0) {
                   add this process to S.L;
                   block;
               }
          }

          void signal(semaphore S) {
               S.value++;
               if (S.value <= 0) {
                   remove a process P from S.L;
                   wakeup(P);
               }
          }
                                                  49
        Deadlock and Starvation of
                        the execution
                                          a V operation § 7.4.3
• Deadlock – two or more processes are waiting indefinitely
  for an event that can be caused by only one of the waiting
  processes.
• Let S and Q be two semaphores initialized to 1
              P0                   P1

           wait(S);             wait (Q);
           wait (Q);            wait (S);
                                   
          signal(S);           signal (Q);
          signal (Q)           signal (S);
• Starvation – indefinite blocking. A process may never be
  removed from the semaphore queue in which it is
  suspended.

                                                              50
        Deadlock and Starvation of
                        the execution
                                        a V operation § 7.4.3
• Deadlock – two or more processes are waiting indefinitely
True-False Question: caused by only one of the waiting
  for an event that can be
( processes.
    ) A deadlock can only happen in between two
• Let S and Q be two semaphores initialized to 1
     processes.
             P0                   P1

        wait(S);               wait (Q);
        wait (Q);              wait (S);
 Answer: ×                        
       signal(S);             signal (Q);
       signal (Q)             signal (S);
• Starvation – indefinite blocking. A process may never be
  removed from the semaphore queue in which it is
  suspended.

                                                             51
         Binary Semaphores
                                           § 7.4.4

• Counting semaphore – integer value can
  range over an unrestricted domain.
• Binary semaphore – integer value can range
  only between 0 and 1; can be simpler to
  implement.
• Can implement a counting semaphore S as a
  binary semaphore.

                                                 52
Implement counting semaphore S
  • Data structures:
         binary-semaphore S1, S2;
         int C:
  • Initialization:
         S1 = 1
         S2 = 0
         C = initial value of semaphore S

                                            53
Implement counting semaphore S
 • wait operation
       wait(S1);
       C--;
       if (C < 0) {
            signal(S1);
            wait(S2);
       }
       signal(S1);
 • signal operation
       wait(S1);
       C ++;
       if (C <= 0)
            signal(S2);
       else
            signal(S1);
                                 54
       Classical Problems of
                                § 7.5
         Synchronization
• Bounded-Buffer Problem
• Readers and Writers Problem
• Dining-Philosophers Problem




                                        55
         Bounded-Buffer Problem              § 7.5.1
• Shared data
        semaphore full, empty, mutex;
  Initially:
        full = 0, empty = n, mutex = 1
• Bounded-Buffer Problem Producer Process:
  do {
                …
         produce an item in nextp
                 …
         wait(empty);
         wait(mutex);
                 …
         add nextp to buffer
                 …
         signal(mutex);
         signal(full);
         } while (1);                             56
         Bounded-Buffer Problem
• Bounded-Buffer Problem Consumer Process:
  do {
         wait(full)
         wait(mutex);
                  …
         remove an item from buffer to nextc
                  …
         signal(mutex);
         signal(empty);
                  …
         consume the item in nextc
                  …
         } while (1);


                                               57
       Bounded-Buffer Problem
•Multiple Choices Question:
  Bounded-Buffer Problem Consumer Process:
( do ){Consider following program for the consumer
        wait(full)
      process of bounded-buffer problem. Which
        wait(mutex);
      instruction is missing from the blank?
                 …
      (a) wait(empty) (b) wait(mutex) (c) signal(full)
        remove an item from buffer to nextc
      (d) signal(empty)
                 …
       signal(mutex);
                                            Answer: d
do {
       signal(empty);
               wait(full)
               wait(mutex);
                …
                        …
               the item in from
       consume remove an itemnextc buffer to nextc
                …       …
               signal(mutex);
               (1);
       } while _______________
                         …
                consume the item in nextc
                         …
        } while (1);
                                                         58
      Readers-Writers Problem                            § 7.5.2


• The readers-writers problem has several
  variations, all involving priorities.
• first: no reader will be kept waiting unless a
  writer has already obtained permission to
  use the shared database.

     No reader should wait for other readers to finish
                 Starvation: writers
           simply because a writer is waiting.

                                                                   59
     Readers-Writers Problem
• second: once a writer is ready, that writer
  performs its write as soon as possible. If a
  writer is waiting to access the object, no
  new readers may start reading.

              Starvation: readers

• Here we present the first solution.
                                                 60
      Readers-Writers Problem
•True-Falseonce a writer is ready, that writer
  second:
            Question:
 performs its write as soon as possible. If a
( ) If a reader will be kept waiting only if a
 writer is waiting to access the object, no
   writer is currently working on the
   database, may start reading.
 new readersthe starvation may happen on
     the reader.
              Starvation: readers
    Answer: ×

• Here we present the first solution.
                                                 61
Readers-Writers Problem: Writer
• Shared data
       semaphore mutex, wrt;
  Initially
       mutex = 1, wrt = 1, readcount = 0

• The writer process:
       wait(wrt);
               …
              writing is performed
               …
       signal(wrt);


                                           62
Readers-Writers Problem: Reader
   wait(mutex);
   readcount++;
   if (readcount == 1)
                wait(wrt);
   signal(mutex);
                 …
         reading is performed
                 …
   wait(mutex);
   readcount--;
   if (readcount == 0)
         signal(wrt);
   signal(mutex):
                                  63
Readers-Writers Problem: Reader
     wait(mutex);
     readcount++;
True-False Question:
     if (readcount == 1)
( ) Although there are many readers
                  wait(wrt);
    working on the database, the semaphore
     signal(mutex);
    mutex will be acquired (wait operation)
                   …
           reading is performed
    and released (signal operation) by the
    same reader. …
     wait(mutex);
     readcount--;
     if (readcount == 0)
  Answer: ×
           signal(wrt);
     signal(mutex):
                                              64
 Dining-Philosophers Problem
                                              § 7.5.3
• A classic synchronization problem
  because it is an example of a large class
  of concurrency-control problems.




                                                    65
 Dining-Philosophers Problem
• Simple solution: represent each chopstick
  by a semaphore.
  Get the chopstick: wait
  Release the chopstick: signal
• Shared data:
     semaphore chopstick[5];

  Initially all values are 1

                                              66
  Dining-Philosophers Problem
 • Philosopher i:
                  do {
                     wait(chopstick[i])
                     wait(chopstick[(i+1) % 5])
                         …
Deadlock when all       eat
five philosophers        …
                     signal(chopstick[i]);
get her left         signal(chopstick[(i+1) % 5]);
chopstick at the         …
same time               think
                         …
                     } while (1);




                                                     67
   Dining-Philosophers Problem
  • Philosopher i:
                   do {
                       wait(chopstick[i])
Multiple Choices Question:
                       wait(chopstick[(i+1) % 5])
                           …
( ) In Dining-Philosophers Problem, if all
 Deadlock when all        eat
    philosophers
 five philosophers get their right chopstick at the
                           …
    same time, what signal(chopstick[i]);
 get her left          will happen?
                       signal(chopstick[(i+1) % 5]);
    (a) starvation (b) deadlock (c) blocking
 chopstick at the          …
    (d) synchronizationthink mutual exclusioncc
 same time                  (e)
                           …
                       } while (1);
  Answer: b


                                                       68
   Dining-Philosophers Problem
• Preventing deadlock by placing restrictions:
   – Allow at most four philosophers to be sitting
     simultaneously at the table.
   – Allow a philosopher to pick up only if both chopsticks
     are available.
   – Use an asymmetric solution
     (for example, an odd philosopher picks up left then right, whereas
     an even philosopher picks up her right chopstick and then her left.)




                                                                            69

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:38
posted:7/27/2012
language:
pages:69