Question

Modify the reader/writer code so that if a writer shows up, no more readers are admitted...

Modify the reader/writer code so that if a writer shows up, no more readers are admitted until at least one writer is served guaranteeing no starvation.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

READERS-WRITERS PROBLEM WITH WRITERS PRIORITY

In this operation

  1. A writer request to enter into critical section

  2. If allows, it perform writing, otherwise wait

  3. If one writer is writing no one can read or write

  4. When one writer completes write operation, the processor checks for if there is any other process request for write operation.

    1. If YES, that process get allocated the critical section

    2. if NO, check for read operations requested by the processes

  5. Ensures all the write requests are allocated before allocating critical section to the read requests.

For this opeartion

  • we use two semaphores

    1. mutex : to ensure mutual exclusion during the operation

    2. wrt : to perform read and write operations

  • write count, wc : to check number of process requests write operation. Wc is initialized as 0.

Functions used in this operation

  1. wait() : used to decrement the semaphore value.

  2. Signal() : used to increment the semaphore value

Program (In question programming language is not mentioned. SO YOU CAN CONSIDER THIS AS A PSEUDO CODE)

do {

// writer requests for critical section

wait(mutex):

// number of writers count increased by 1

wc++;

do {

// loop to continue allocating write processes

if(wc == 1)

wait(wrt);

// this is to ensure that no readers can under if there atleaset one writer

// WRITER PERFOMR WRITE OPERATION

// only one writer can write at a time

wait(mutex); // a writer wants to leave

wc--;

}while(wc != 0);

if(wc == 0)

signal(wrt); //readers can enter

signal(mutex); // writer leaves

}while(true);

Process

  1. Writer request to enter into critical section

  2. if the request is accepted,

    1. Writer count wc is incremented.

    2. Check it is first writer(wc = 1). If true, it locks the wrt semaphore to block any other readers to enter.

    3. Performs the write operation. Only one writer can perform at a time

    4. After completion, wc is decremented by 1 when one writer leaves.

    5. If wc is not zero perform the write operation again

  3. If not accept, it should wait

  4. After all write operations completed, signal the wrt which allows other readers can enter

Add a comment
Know the answer?
Add Answer to:
Modify the reader/writer code so that if a writer shows up, no more readers are admitted...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Modify your code from the previous exercise so that it could easily be modified to display...

    Modify your code from the previous exercise so that it could easily be modified to display a different range of numbers (instead of 1234567890) and a different number of repetitions of those numbers (instead of 60 total characters), with the vertical bars still matching up correctly. Write a complete class named NumbersOutput. Use two class constants instead of "magic numbers,", with one constant set to 6 for the number of repetitions, and the other set to 10 for the range...

  • For this lab, modify the python code below so it will continuously be asking user for...

    For this lab, modify the python code below so it will continuously be asking user for inputs to calculate the interest earned until the user enters number 0 (zero) in principle. Once the user enters any number less or equal to 0 in principle, the program will end. here is my code: # Programming Exercise 3-14 # Local variables p = 0.0 r = 0.0 n = 0.0 t = 0.0 loop = True while loop: p = float(input('\nEnter the...

  • #Python Help please Modify the mistakes in my code , so that it prints the same...

    #Python Help please Modify the mistakes in my code , so that it prints the same statement four times. Using four distinct techniques—hard-coding, commas, concatenation, and string formatting. The hard-coding is already done. The other three techniques have been started but they contain mistakes. These techniques should each use all three of the provided variables. Once the mistakes have been corrected, run the script and upload a picture of the program running to make sure that it prints the statement...

  • Instructions: Written in English (Basic Language) Modify the Base Project Sample Code to create a database...

    Instructions: Written in English (Basic Language) Modify the Base Project Sample Code to create a database of your own design that includes at least four data fields. The overall design and format of your program is up to you. Your program should implement the following menu options – A. Add Item B. List All Items C. Quit Any data theme or motif is acceptable, provided your project has at least four data elements. Please make sure your data structure implements...

  • In the last assignment, you created a card class. Modify the card class so the setValue()...

    In the last assignment, you created a card class. Modify the card class so the setValue() method does not allow a card’s value to be less than 1 or higher than 13. If the argument to setValue() is out of range, assign 1 to the card’s value. You also created a PickTwoCards application that randomly selects two playing cards and displays their values. In that application, all card objects were arbitrarily assigned a suit represented by a single character, but...

  • C++ edit: You start with the code given and then modify it so that it does...

    C++ edit: You start with the code given and then modify it so that it does what the following asks for. Create an EmployeeException class whose constructor receives a String that consists of an employee’s ID and pay rate. Modify the Employee class so that it has two more fields, idNum and hourlyWage. The Employee constructor requires values for both fields. Upon construction, throw an EmployeeException if the hourlyWage is less than $6.00 or over $50.00. Write a program that...

  • Complete the code so that the program makes the expected output. Use no more than one...

    Complete the code so that the program makes the expected output. Use no more than one word in the blank. Expected output: adam_smith for ch in "[email protected]": if ch == "@": _________ print(ch, end="")

  • I need help in Python. This is a two step problem So I have the code...

    I need help in Python. This is a two step problem So I have the code down, but I am missing some requirements that I am stuck on. Also, I need help verifying the problem is correct.:) 7. Random Number File Writer Write a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 500. The application should let the user specify how many random numbers the file...

  • Can someone modify my code so that I do not get this error: Exception in thread...

    Can someone modify my code so that I do not get this error: Exception in thread "main" java.lang.NullPointerException at java.awt.Container.addImpl(Container.java:1043) at java.awt.Container.add(Container.java:363) at RatePanel.<init>(RatePanel.java:64) at CurrencyConverter.main(CurrencyConverter.java:16) This code should get the amount of money in US dollars from user and then let them select which currency they are trying to convert to and then in the textfield print the amount //********************************************************************* //File name: RatePanel.java //Name: Brittany Hines //Purpose: Panel for a program that convers different currencyNamerencies to use dollars //*********************************************************************...

  • C++: modify the following code so the names of the month are listed to the left...

    C++: modify the following code so the names of the month are listed to the left of the high and low temperature readings and label the two columns of numbers as high (the one on the left) and low (the one on the right). Numbers are already in order so all that is needed is the months' names in order from top (jan.) to bottom (dec.) code: #include <iostream> #include <fstream> #include <iomanip> using namespace std; const int NO_OF_MONTHS =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT