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

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

3675


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?

3125


write a function that reverse the elements of an array in place.The function must accept only one pointer value and return void.

4230


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.

2279


find level of following tree (state, parent) " J,D I,D H,C E,B F,B G,C B,A D,A C,A A,& K,E L,E L,F M,F N,G O,H P,I P,H Q,I R,J S,K U,P T,L

2211






write a program to perform generic sort in arrays?

2799


Create a program to read two random data set in two files named data1.txt and data2.txt manifold contains integer numbers, whereas data2.txt file contains the float type numbers. Simpanlahmasing each into 2 pieces of data that is an array of type integer array and an array of type float, then calculate the average numbers in the second array.

2359


Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE.

4760


Teta-Omeg-Big-Oh Show that f(n) = n2 + 3n3 is ;(n3).

3369


Performance Algorithm A performs 10n2 basic operations and algorithm B performs 300 lg n basic operations. For what value of n does algorithm B start to show its better performance?

7600


write a function that allocates memory for a single data type passed as a parameter.the function uses the new operator and return a pointer to the allocated memory.the function must catch and handle any exception during allocation

2616


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.

2263


Code for Method of Handling Factorials of Any Size?

2177


3. Program to find the Sum of give series. a. (1)+(1+2)+(1+2+3)+(1+2+3+4)+……………………………….. b. 1/1+1/9+1/25+1/49+……………...

4568


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

2762