Readers & Writers Problem (Priority over Writers)

 

 

What is Readers & Writers Problem? 

            Different from others this problem models the access to a database system. A bank system can be an example for this problem. In same disk area many processes may need read/write operations. Many read operations at the same time are acceptable but different write requests cause data to vanish. This problem is solved by giving priority over read operations.

Here the Readers & Writers problem was solved differently by giving priority over write operations, which is symmetric with the reader’s algorithm. Below there is the pseudo-code for writer’s algorithm.

 

 

            read = 1           mutex = 1        writecount = 0 

 

This code supports n processes.

 

 

Readers

Writers

wait(read);

            READING IS PERFORMED

signal(read);

            wait(mutex);

                        writecount = writecount + 1;

                        if (writecount = 1)

                                    wait(read);

            signal(mutex);

                        WRITE IS PERFORMED

            wait(mutex);

                        writecount = writecount - 1;

                        if (writecount = 0)

                                    signal(read);

            signal(mutex);

 

 

 

 

 

References

[1]  Tanenbaum, Andrew S., Modern Operating Systems, Second Edition, Prentice Hall, Chapter2, page 128, 2002.

 

 
Copyright by Chasan Chouse