Page 118 - DCAP103_Principle of operating system
P. 118

Unit 4: Process Management-III



                                                                                                  Notes
                                      Figure 4.2: Critical Section B

                                Wait S
                                                              Enter

                                     Critical
                                     Section

                                                              Exit
                                Signal S

            The key to preventing trouble involving shared storage is find some way to prohibit more than
            one process from reading and writing the shared data simultaneously. That part of the program
            where the shared memory is accessed is called the Critical Section. To avoid race conditions and
            flawed results, one must identify codes in Critical Sections  in each thread. The characteristic
            properties of the code that form a Critical Section are:
               •  Codes that reference one or more variables in a “read-update-write” fashion while any of
                 those variables is possibly being altered by another thread.

               •  Codes that alter one or more variables that are possibly being referenced in “read-updata-
                 write” fashion by another thread.

               •  Codes use a data structure while any part of it is possibly being altered by another thread.

               •  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.

                          Part of the program where the shared memory is accessed is called the
                          Critical Section.


            4.2 The Critical Section Problem


            n  processes  all  competing  to  use  some  shared  data.  Each  process  has  a  code  segment,
            called  critical  section,  in  which the  shared data  is accessed. Problem  –  ensure  that  when
            one  process  is  executing  in  its  critical  section,  no  other  process  is  allowed  to  execute  in
            its critical section. Structure of process Pi repeat entry section critical section exit section
            remainder section until false.

            4.3 Way to Handle 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.






                                             LOVELY PROFESSIONAL UNIVERSITY                                   111
   113   114   115   116   117   118   119   120   121   122   123