Page 106 - DCAP403_Operating System
P. 106

Unit 6: Process Synchronization




          2.   Codes that alter one or more variables that are possibly being referenced in “read-updata-  Notes
               write” fashion by another thread.
          3.   Codes use a data structure while any part of it is possibly being altered by another thread.
          4.   Codes alter any part of a data structure while it is possibly in use by another thread.

          Here, the important point is that when one process is executing shared modifiable data in its
          critical section, no other process is to be allowed to execute in its critical section. Thus, the
          execution of critical sections by the processes is mutually exclusive in time.

                                       Figure 6.3: Critical Section
                              Wait S
                                                            enter


                                  Critical Section

                                                            exit
                              Signal S

          A way of making sure that if one process is using a shared modifiable data, the other processes

          will be excluded from doing the same thing.
          Formally, while one process executes the shared variable, all other processes desiring to do so

          at the same time moment should be kept waiting; when that process has finished executing the

          shared variable, one of the processes waiting; while that process has finished executing the shared
          variable, one of the processes waiting to do so should be allowed to proceed. In this fashion, each
          process executing the shared data (variables) excludes all others from doing so simultaneously.
          This is called Mutual Exclusion.




             Note    Mutual exclusion needs to be enforced only when processes access shared


             modifiable data - when processes are performing operations that do not conflict with one
             another they should be allowed to proceed concurrently.
          6.2.1 Mutual Exclusion Conditions

          If you could arrange matters such that no two processes were ever in their critical sections
          simultaneously, you could avoid race conditions. You need four conditions to hold to have a
          good solution for the critical section problem (mutual exclusion).

          1.   No two processes may at the same moment inside their critical sections.
          2.   No assumptions are made about relative speeds of processes or number of CPUs.
          3.   No process outside its critical section should block other processes.
          4.   No process should wait arbitrary long to enter its critical section.

          6.2.2 Proposals for Achieving Mutual Exclusion

          The mutual exclusion problem is to devise a pre-protocol (or entry protocol) and a post-protocol
          (or exist protocol) to keep two or more threads from being in their critical sections at the same
          time.





                                           LOVELY PROFESSIONAL UNIVERSITY                                    99
   101   102   103   104   105   106   107   108   109   110   111