Answered step by step
Verified Expert Solution
Question
1 Approved Answer
These are part of same problem. Please solve all faster properly. I do not need that much details. just make sure the right answer.. I
These are part of same problem. Please solve all faster properly. I do not need that much details. just make sure the right answer.. I just need the correct answer.
You can use shortcuts but please give solve as fast as possible.
I am running Out of time.
PLEASE DO SUPERFASTLY
Question:
3. [8] a) Remember this readers-writers synchronization problem from BUX and the reference book. do wait (mutex); read_count++; if (read_count == 1) wait (rw_mutex); signal (mutex); /* reading is performed */ do { wait (rw_mutex); /* writing is performed */ signal(rw_mutex); } while (true); wait(mutex); read_count--; if (read_count == 0) signal (rw_mutex); signal (mutex); } while (true); Figure 5.11 The structure of a writer process. Figure 5.12 The structure of a reader process. a This solution solves the critical section problem. However, there is starvation issue here for the writer process. If there is a steady stream of reader processes in the ready queue, the writer process may starve and may not be able to write. We hope you can solve this starvation issue by applying one restriction in the code. The restriction is that if the writer was waiting for a reader, then that reader cannot read again before the writer completes writing. If more than one reader were reading when the writer was waiting this restriction applies to all those readers. Update the reader and writer code to implement this restriction. HINTS: You do not need any additional mutex for this but need to use both mutexes in both programs. You need a flag variable shared among the writer and readers to indicate if the writer is waiting. Call it the writer_waiting flag. You need a private variable in the reader process, call it i_kept_writer_waiting, so that a reader can remember when starting its next iteration that the writer was waiting when it was reading in the previous iteration. [6] b) For Peterson's problem, the conditions below will apply. Each statement will take 3ms to complete. For process o: i=0,j=1; and for process 1: i=1,j=0. Context switching will occur after every 9ms. In the critical section area, there are only 2 statements. The remaining section area contains only 1 statement. Information common to both processes: turn=0; flag[0]=FALSE; flag[1]=FALSE; Complete the following table up to 45ms in the timeline considering the above conditions and information. In the table, you will write the corresponding lines of code each process executes in that time slot. Process o Process 1 Time 45 The pseudocode for Peterson's solution is given below for any process Pi, do { flag[i] = true; turn = j; while (flag[j] && turn == j); critical section flag[i] = false; remainder section } while (true); [3] a c) We all know the producer-consumer problem. Explain in general terms, how solution to the producer-consumer problem can help to serve the guests in a 3. [8] a) Remember this readers-writers synchronization problem from BUX and the reference book. do wait (mutex); read_count++; if (read_count == 1) wait (rw_mutex); signal (mutex); /* reading is performed */ do { wait (rw_mutex); /* writing is performed */ signal(rw_mutex); } while (true); wait(mutex); read_count--; if (read_count == 0) signal (rw_mutex); signal (mutex); } while (true); Figure 5.11 The structure of a writer process. Figure 5.12 The structure of a reader process. a This solution solves the critical section problem. However, there is starvation issue here for the writer process. If there is a steady stream of reader processes in the ready queue, the writer process may starve and may not be able to write. We hope you can solve this starvation issue by applying one restriction in the code. The restriction is that if the writer was waiting for a reader, then that reader cannot read again before the writer completes writing. If more than one reader were reading when the writer was waiting this restriction applies to all those readers. Update the reader and writer code to implement this restriction. HINTS: You do not need any additional mutex for this but need to use both mutexes in both programs. You need a flag variable shared among the writer and readers to indicate if the writer is waiting. Call it the writer_waiting flag. You need a private variable in the reader process, call it i_kept_writer_waiting, so that a reader can remember when starting its next iteration that the writer was waiting when it was reading in the previous iteration. [6] b) For Peterson's problem, the conditions below will apply. Each statement will take 3ms to complete. For process o: i=0,j=1; and for process 1: i=1,j=0. Context switching will occur after every 9ms. In the critical section area, there are only 2 statements. The remaining section area contains only 1 statement. Information common to both processes: turn=0; flag[0]=FALSE; flag[1]=FALSE; Complete the following table up to 45ms in the timeline considering the above conditions and information. In the table, you will write the corresponding lines of code each process executes in that time slot. Process o Process 1 Time 45 The pseudocode for Peterson's solution is given below for any process Pi, do { flag[i] = true; turn = j; while (flag[j] && turn == j); critical section flag[i] = false; remainder section } while (true); [3] a c) We all know the producer-consumer problem. Explain in general terms, how solution to the producer-consumer problem can help to serve the guests in aStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started