Question
pleasw answer as soon as possible . this is for my exam practice . please read the code and answer the question

In a system, there are multiple reader processes which read from a shared file and multiple writer processes which update a s
6. How should the shared variable readCount, and the semaphores mutex and writeBlock be initialized so that the system would
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Greetings!!

6. Initial values of the variables

  • readCount is an integer variable used for couting the number of reader processes and
  • mutex and writeBlock are binary semaphore variables which are initialized with 1
  • readCount will increment as the reader processes are entering into the code
  • mutex and writeBlock are used for atomic execution of the Critical Section and readCount update

7. When the writer process is executing the CS, the first reader process will do P(mutex) so that all the other reader processes will be waiting here since no more P(mutex) is possible. First reader will be updating the readCount and will be waiting on P(writeBlock) which is already decremented by the writer process. Once the writer process exit from the CS and do V(writeBlock), the first reader can enter into the CS. Before enter into the CS, first reader will do V(mutex) so that the other waiting reader can enter into the CS one by one.

Reader Process // Non-Critical Section P(mutex); readers will wait here readCounter++; if (readCounter 1) P(writeLock); First

8. When the first reader enter into the program, it set the readCounter as 1 and do P(writeBlock) so that writer cannot enter into the Writer Process. But other readers can enter into CS of Readers Process one by one using P(mutex) and V(mutex). When the last reader is exiting from the code, it do V(writeBlock) so that the writer process can enter into the CS of Writer Process.

9. Suppose a situation where the readers processes are continuing in the CS of the Reader Process, either the existing reader is not leaving the CS or new readers are entering into the CS. In such case, the writer process will never enter into the CS of the Writer Process since the value of writeBlock is 0.

10. Using another binary semaphore variable XYZ, which stops new readers, once a writer has come and waiting to enter into the CS of the writer process. So once all the reader processes exits which are inside the CS, the writer process is allowed inside the CS and hence no more starvation for the writer process.

Hope this helps

Thank You

Add a comment
Know the answer?
Add Answer to:
pleasw answer as soon as possible . this is for my exam practice . please read...
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
  • please i need as soon as possible thank you A classical concurrent programming problem is called...

    please i need as soon as possible thank you A classical concurrent programming problem is called readers and writers. A data area is shared between several processes. Some processes, the writers, write to the area, the others, the readers, only read the data. At any given time only one reader can read the data or writer can write to the data. Also, no readers are allowed while a writer is executing. Problem Statement: Devise suitable semaphores for this situation and...

  • operating system engineering , please read the question and solve on the given skeleton code ....

    operating system engineering , please read the question and solve on the given skeleton code . Write a multi-threaded program with Semaphores as counters and pthread_mutex_t mutex to solve the producer-consumer problem: A bounded buffer is simply a global integer array of size N (2) which can be accessed by multiple threads. • Create two types of threads - Producer (2) and Consumer (2). Producers will write to the buffer, and the consumers will read the buffer. In this scenario,...

  • TRUE-FALSE     Basic synchronization principles and multithreading 1. Java user threads can implement both busy-waiting and no-busy-waiting...

    TRUE-FALSE     Basic synchronization principles and multithreading 1. Java user threads can implement both busy-waiting and no-busy-waiting policy. 2. Priority inversion avoids deadlocks. 3. Spinlock mutex can be used as an adaptive mutex. 4. Java RTE can be blocked for Input/Output operation. 5. Interrupted user thread, which executes a method in a monitor, must be rolled back to undo any changes it performed. 6. The synchronization primitive by disabling interrupts can be used by an application program. 7. Bounded-waiting requirement is...

  • I know is this posted else where BUT I NEED HELP IMPLEMENTING THE TIME DELAY!!!! I...

    I know is this posted else where BUT I NEED HELP IMPLEMENTING THE TIME DELAY!!!! I need a source comment next to the line that gives the delay so i can compare please. (Concurrency – Semaphores) 1.- In this assignment you will implement a deadlock free variant of the bounded-buffer producer/consumer using jBACI (C - -). C- - is a subset of C + + that allows you to declare semaphores and apply the operations P and V. In the...

  • I have the following code....from the previous lab....the above needs to be added to what is...

    I have the following code....from the previous lab....the above needs to be added to what is already existing. ALSO MODIFY SEMAPHORES TO USE pthreads instead of the pipe constructs P() & V() #include <stdio.h> #include <string.h> #include <sys/types.h> #include <unistd.h> #include <sys/wait.h> #include <stdlib.h> #include <sys/stat.h> void printStat(char *filename); //Main int main(int argc, char *argv[]) { //Process Id (storing)    pid_t pid;    int j;    //printf("Welcome to Project Three\n”);    // For loop*/    for (j = 1; j...

  • Please answer question correctly and show the result of the working code. The actual and demo...

    Please answer question correctly and show the result of the working code. The actual and demo code is provided .must take command line arguments of text files for ex : input.txt output.txt from a filetext(any kind of input for the text file should work as it is for testing the question) This assignment is about using the Java Collections Framework to accomplish some basic text-processing tasks. These questions involve choosing the right abstraction (Collection, Set, List, Queue, Deque, SortedSet, Map,...

  • Question I This question carries 20% of the marks for this assignment. You are asked to...

    Question I This question carries 20% of the marks for this assignment. You are asked to develop a set of bash shell script: Write a script that asks for the user's salary per month. If it is less or equals to 800, print a message saying that you need to get another job to increase your income, what you earn is the Minim living cost. If the user's salary is higher than 800 and below 2000, print a message telling...

  • please answer as soon as possible. i only have 37 minutes left. i need help determining...

    please answer as soon as possible. i only have 37 minutes left. i need help determining whether or not the examples are word for word plagarism, paraphrasing plagarism, or not plagarism at all 14% Sun 12 29:06 AM Christoph Window Help Edi Safari Fle View History Bookmarks indiane edua In The Case Below The Original Source to How to Recognine PagiaemUndergraduate Cerication Tests: Se. Plagasm Ceficate Item 1 View In the case below, the original source material is given along...

  • Please answer question 1-4 4. Vocabulary: Match definition to its word. There will be some words...

    Please answer question 1-4 4. Vocabulary: Match definition to its word. There will be some words left over. (DUP some words left over. (50 points, 5 points each) part of the processor that performs actions such as mathematics, testing, and moving data the processor uses this computed memory location to access data used to combine multiple partial programs into a single executable how instructions are stored as machine code A. Indirect B. event handler c. pointer D. assembler E. control...

  • Please provide original Answer, I can not turn in the same as my classmate. thanks In...

    Please provide original Answer, I can not turn in the same as my classmate. thanks In this homework, you will implement a single linked list to store a list of computer science textbooks. Every book has a title, author, and an ISBN number. You will create 2 classes: Textbook and Library. Textbook class should have all above attributes and also a “next” pointer. Textbook Type Attribute String title String author String ISBN Textbook* next Textbook Type Attribute String title String...

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