Page 105 - DCAP403_Operating System
P. 105

Operating System




                    Notes          device driver. At this point, the operating system must decide whether to grant this request,
                                   depending upon whether the printer is already being used by another process. If it is not, the
                                   operating system should grant the request and allow the process to continue; otherwise, the
                                   operating system should deny the request and perhaps classify the process as a waiting process
                                   until the printer becomes available. Indeed, if two processes were given simultaneous access to
                                   the machine’s printer, the results would be worthless to both.

                                   Now that the problem of synchronization is properly stated, consider the following related
                                   defi nitions:
                                   1.   Critical Resource: A resource shared with constraints on its use (e.g., memory,  fi les,
                                       printers, etc.)
                                   2.   Critical Section: Code that accesses a critical resource
                                   3.   Mutual Exclusion: At most one process may be executing a Critical Section with respect to
                                       a particular critical resource simultaneously
                                                       Figure 6.2: Railway-road Intersection with Signal





















                                   In the example given above, the printer is the critical resource. Let’s suppose that the processes
                                   which are sharing this resource are called process A and process B. The critical sections of process
                                   A and process B are the sections of the code which issue the print command. In order to insure
                                   that both processes do not attempt to use the printer at the same, they must be granted mutually
                                   exclusive access to the printer driver. The idea of mutual exclusion with our railroad intersection
                                   by adding a semaphore to the picture.
                                   Semaphores are used in software systems in much the same way as they are in railway systems.
                                   Corresponding to the section of track that can contain only one train at a time is a sequence of
                                   instructions that can be executed by only one process at a time. Such a sequence of instructions
                                   is called a critical section.

                                   6.2 Critical Selection Problem



                                   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:
                                   1.   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.





          98                               LOVELY PROFESSIONAL UNIVERSITY
   100   101   102   103   104   105   106   107   108   109   110