Read-write locks, Operating System

Consider a large web-based database. In some sense, Google is sort of like this. There might be many users who want to read from the database, but only a few users who are allowed to write to the database. If we use standard locks to control access to the database, the application will be much slower than it could be with a more clever type of lock.

Suppose we have one object that is shared among several threads. Suppose also that each thread is either a reader or a writer. Readers only read data but never modify it, while writers read and modify data. If we know which threads are reading and which ones are writing, what can we do to increase concurrency?

First, we have to prevent two writers from writing at the same time. In addition, a reader cannot read while a writer is writing. There is no problem, however in allowing lots of readers to read at the same time. Read-write locks achieve this, and can greatly improve performance for this sort of application.

Note that the lock is the same for both readers andwriters (called 'rw' in the slides), but the readers use an rlock() on the lock and writers use a wlock() on the same lock. Writers requesting a wlock() will have to wait until all readers and writers have released the lock. Readers requesting a rlock() can acquire it even if other readers are holding the lock. Readers however will still have to wait until any writer holding the lock releases the lock.

Posted Date: 3/12/2013 5:28:34 AM | Location : United States







Related Discussions:- Read-write locks, Assignment Help, Ask Question on Read-write locks, Get Answer, Expert's Help, Read-write locks Discussions

Write discussion on Read-write locks
Your posts are moderated
Related Questions
What is the main advantage of multiprogramming? Multiprogramming makes efficient use of the CPU by overlapping the demands for the CPU and its I/O devices from various users. I

Define the Sleep (sec) Function Sleep function suspends execution of this process for sec number of seconds. While this function is used in our example for consistency, other f

Write an application that does the following:(1) fill an array with 50 random integers; (2) loop through the array, displaying each value, and count the number of negative values;

Relative file organization A relative file is an array of fixed-length slots and the records can be inserted in the first free slot found from the beginning of the file and

socket based fortune teller sever.your program should create a server that listens to a specific port when a client receives a connection the server should respond with a random fo


Essential Properties of Operating System 1. Batch: Jobs with similar needs are batched together and run through the computer as a group by an operator or automatic job sequen

Question : (a) In the demand paging system, when a process tries to access a page that was not brought into memory, a page fault occurs that involves a series of actions. The

Q. Data transfer between two processes? Communication: Data transfer between two processes is essential for some time. Both processes are on the one computer or on different

When do we write a page from physical memory back to the disk? In general, caches have two broad types of writing policies. One approach is a write-through cache. In this case,