<< Previous page

Next page >>



 
MUTUAL EXCLUSION IN DISTRIBUTED SYSTEM


.  What is the need of mutual exclusion in distributed systems?

    Let us answer the above question with an example.
    Consider a distributed system. Suppose it is desired to find out the number of lines a big project.

    Let us assume that there are n files in the project and m CPU's in the distributed system.

    Cpu1 reads file1 and counts the number of lines in it and adds the value to the
    system-wide global shared variable no_of_lines.

    Cpu2 reads file2 and counts the number of lines in it and adds the value to the
    system-wide global shared variable no_of_lines.

    All the above processes are executed simultaneously in the distributed system.

    Consider what happens if two processes attempts to increment the shared variable
    no_of_lines simultaneously.

    Each process has to perform the following instructions.

                load no_of_lines
                add no_of_lines_in_the_current_file
                store no_of_lines

     Now, say current value of no_of_lines is 6000 and process1 tries to add 50 to it whereas
      process2 tries to add 100 to it.
    Assume process1 and process2 reads no_of_lines from the memory at the same time.
    Now, process1 adds   50 to 6000 to make it 6050 and stores 6050 in the variable no_of_lines.
    At the same time, process2 adds 100 to 6000 to make it 6100 and stores 6100 in the variable no_of_lines.

     Now, the value of the variable no_of_lines can be 6050 if process1 executes the store no_of_lines
     command after process2.
     Now, the value of the variable no_of_lines can be 6100 if process2 executes the store no_of_lines
     command after process1.

    But, we want 6150 (6000+50+100) to be stored in no_of_lines.
    In both cases the answer we want is not stored in the variable no_of_lines.

    Because of the uncontrolled access to the shared variable no_of_lines, the system has essentially
    lost track of the number of lines.

    The key cause of this incorrect result is the writing of the shared variable. Clearly many concurrent
    process may read data simultaneously without this difficulty.
    But, when one process reads data that another process may be writing, or when one process
    writes data that another process may also be writing, then indeterminate results occur.

    The problem can be solved by giving each process exclusive access to the shared variable.
    while one process is updating the shared data , then all other processes wishing to do the same
    should be kept waiting till that process has finished updating the shared data.

    In this way, each process accessing the shared data excludes all others from doing so simultaneously.

    This is called mutual exclusion.
 

<< Previous page

Next page >>