Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How reader and writer problem was implemented and come up
with effective solution for reader and writer problem in
case we have n readers and 1 writer.

Answer Posted / raj kumar

Readers: read data, never modify it
Writers: read data and modify it
criteria:
– Each read or write of the shared data must happen within
a critical section.
– Guarantee mutual exclusion for writers.
– Allow multiple readers to execute in the critical section
at once.
In this example, semaphores are used to prevent any writing
processes from changing information in the database while
other processes are reading from the database.
semaphore mutex = 1; // Controls access to
the reader count
semaphore db = 1; // Controls access to
the database
int reader_count; // The number of
reading processes accessing the data

Reader()
{
while (TRUE) { // loop forever
down(&mutex); // gain access
to reader_count
reader_count = reader_count + 1; // increment the
reader_count
if (reader_count == 1)
down(&db); // if this is
the first process to read the database,
// a down on db
is executed to prevent access to the
// database by a
writing process
up(&mutex); // allow other
processes to access reader_count
read_db(); // read the database
down(&mutex); // gain access
to reader_count
reader_count = reader_count - 1; // decrement
reader_count
if (reader_count == 0)
up(&db); // if there are
no more processes reading from the
// database,
allow writing process to access the data
up(&mutex); // allow other
processes to access reader_countuse_data();
// use the data
read from the database (non-critical)
}

Writer()
{
while (TRUE) { // loop forever
create_data(); // create data
to enter into database (non-critical)
down(&db); // gain access
to the database
write_db(); // write
information to the database
up(&db); // release
exclusive access to the database
}

Is This Answer Correct ?    3 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

develop a program to calculate and print body mass index for 200 employees

2654


can you please write a program for deadlock that can detect deadlock and to prevent deadlock.

3229


how to write a program that opens a file and display in reverse order?

3056


Write a (n) algorithm that sorts n distinct integers, ranging in size between 1 and kn inclusive, where k is a constant positive integer. (Hint: Use a kn-element array.)

4980


write a program that can LOCATE and INSERT elements in array using c++ programming languages.

4012


how to diplay a external image of output on winxp by using c & c++,

3438


write a program to calculate the amount of investment after a period n years if the principal investors was p and interest is calculated using compound interest,formular=a=p(1+r)^n

2851


i really need help about this.. write a program to display the set of odd and even numbers separately. find the highest and lowest value of the given numbers.

2703


Code for Two Classes for Doing Gzip in Memory?

3251


solve the problem in the programming language C++"if a five digit number is input through the keyboard.Write a program to calculate the sum of its digits(hint: use the modulus operator)

3407


Code for Easily Using Hash Table?

3017


Write a program that print in screen a tree with its height taken from user by entering number of 4 digits and find the odd numbers then calculate the sum of odd numbers so he get the height of tree?

3349


write a program that reverses the input number of n.Formulate an equation to come up with the answer.

7673


Code for Method of Handling Factorials of Any Size?

2475


Code for Small C++ Class to Transform Any Static Control into a Hyperlink Control?

3051