readers and writers problem



readers and writers problem..

Answer / fk

In this lab you will simulate one of the classical synchronization problems in order to see how the (semi) critical section problem could be implemented using binary and counting semaphores.
5 processes are characterized by 3 readers and 2 writers.
Up to two reader processes can be inside their critical section without any writer process. For writer process to go into its critical section, it should check whether there is any reader or writer process is in the critical section.
Critical section in this problem is reading shared data buffer for reader and updating shared data buffer for writer processes. It is up to you to implement any shared data for readers and writers but you have to specify clearly following things in your sample output.
• When reader or writer enters its critical section, it has to report whether there are any reader(s) or writer(s) other than itself.
• You may print out the data you read or write when you implement real buffer. (Optional)
• You have to print out “Panic Messages” when the rules behind this semi critical section problem are not observed.
In your main program, you run the random number generator function to choose process to execute. The chosen process starts (resumes) execution and after one instruction, it will be returned. (You should force each process run exactly one instruction then returns and waiting for its turn.)
You can implement this using switch statement in C++. Each process is one big switch statement and will be returned after each instruction. You need to keep track of program counter of each process to resume at the right place once it will be chosen to run by keeping global counter variable per process.
Subproject 1: You should implement binary and counting semaphores as studied in the class for this project.
Subproject 2: You should implement swap operation as studied in the class for this project.
You should

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ Code Interview Questions

write a c program, using for loop, that accepts and odds two numbers. The output must be the sum and the addens. This should be repeated 5 times while the first number is decremented by one and the second number is incremented by 1.

2 Answers   IBM, Infosys,


Show by induction that 2n > n2, for all n > 4.

2 Answers   Karvy, Qatar University,


What is the time complexity T(n) of the following program? a) int n, d, i, j; cin >> n; for (d=1; d<=n; d++) for (i=1; i<=d; i++) for (j=1; j<=n; j += n/10) cout << d << " " << i << " " << j << endl; b) void main() { int n, s, t; cin >> n; for (s = 1; s <= n/4; s++) {t = s; while (t >= 1) { cout << s << " " << t << endl; t--; } } } c) void main() { int n, r, s, t; cin >> n; for (r = 2; r <= n; r = r * 2) for (s = 1; s <= n/4; s++) { t = s; while (t >= 1) { cout << s << " " << t << endl; t--; } } }

3 Answers   CTS, IBM, Infosys, Qatar University,


write a function – oriented program that calculates the sum of the squares from 1 to n. thus, if the input is 3, the output is 14

3 Answers  


write a program that prompt the user to enter his height and weight,then calculate the body mass index and show the algorithm used

0 Answers   Jomo Kenyatta University,






What output does this program generate as shown? Why? class A { A() { cout << "A::A()" << endl; } ~A() { cout << "A::~A()" << endl; throw "A::exception"; } }; class B { B() { cout << "B::B()" << endl; throw "B::exception"; } ~B() { cout << "B::~B()"; } }; int main(int, char**) { try { cout << "Entering try...catch block" << endl; A objectA; B objectB; cout << "Exiting try...catch block" << endl; } catch (char* ex) { cout << ex << endl; } return 0; }

0 Answers  


Write a program using two-dimensional arrays that determines the highest and lowest of the 12 input values. Example: Enter 12 numbers: 13 15 20 13 35 40 16 18 20 18 20 14 highest: 40 lowest: 13

1 Answers  


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.

0 Answers  


Complexity T(n) What is the time complexity T(n) of the following portions of code? For simplicity, you may assume that n is a power of 2. That is, n = 2k for some positive integer k. a) ? for (i = 1; i <= n; i++) { j = n; cout << i << ? ? j << ? ? << endl; } b) ? for (i = 0; i <= n; i += 2) { j = n; cout << i << ? ? j << ? ? << endl; } c) ? for (i = n; i >= 1; i = i/2) { j = n; cout << i << ? ? j << ? ? << endl; } d) for (i = 1; i <= n; i++) { j = n; while (j >= 0) { cout << i << ? ? j << ? ? << endl; j = j - 2; } }

0 Answers   Qatar University,


what is the use of using for loop as "for(;;)"?

5 Answers   Satyam,


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

0 Answers   Wipro,


Subsets Write an algorithm that prints out all the subsets of 3 elements of a set of n elements. The elements of the set are stored in a list that is the input to the algorithm. (Since it is a set, you may assume all elements in the list are distinct.)

1 Answers   CSC, Qatar University,


Categories