Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

mutexes in both programs. - You need a flag variable shared among the writer and readers to indicate if the writer is waiting. Call it

image text in transcribedmutexes 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. b) For Petersons problem, the conditions below will apply. Each statement will take 3ms to complete. For process 0: 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. The pseudocode for Petersons solution is given below for any process Pi, c) We all know the producer-consumer problem. Explain in general terms, how a solution to the producer-consumer problem can help to serve the guests in a [6] [3] wedding ceremony problem. The food is brought to all the tables then the first batch of guests eat. After the guests complete eating, the tables are again filled with food so that the next batch of guests can start. Dont forget to mention who is the producer, who is the consumer, and what is the buffer in this scenario. Do you need any change in the producer-consumer solution to support this scenario? If yes then explain the change. d) Name the three conditions any solution for the critical section must meet. Give an example of a problem that can happen if any condition is violated for all three conditions.

[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); wait (mutex); read_count--; /* writing is performed */ * if (read_count 0) signal (rw_mutex); signal(rw_mutex); signal (mutex); } while (true); } while (true); Figure 5.11 The structure of a writer process. Figure 5.12 The structure of a reader process. This solution solves the critical section problem. However, there is a 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions