Question

In the class we mentioned briefly the readers-writers problem with writers priority. The problem can be solved in guarded com

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

A reader-writer problem problem occurs when a seeker wants to access a file which is still under modification or, when one modifier want to change the data while other modifier is still using that file. For solving that, we use semaphores. Here, as given by your code, we are using three semaphores:

1. readers: who want to seek the file

2. writers: who want to modify the file

3. active_writers: currently modifying the file.

So, in reader function as we can see, we are checking for only one condition i.e if there are no writers who are modifying the file. If so, we add all the readers. All readers are added because we will not face any problem when it is in read mode. No changes can happen to the file while reading. While reading we can create a mutex lock on this file. Through this lock we can lock the writers to block access to this file. Once reading is finished the lock can be released and file can be closed for reading as readers job is done. Hence, fall-off of the readers.

In writers block we use the remaining semaphores i.e. writers and active_writers. We will increment all the writers who want to use the file. But, only one active_writer is given a chance to use this file as multiple writers can modify the file abnormally. So the condition for writing will be if, no readers are available and if there are no active_writers. Only then we will allow a writer to enter the file and make modifications. In this process, we can keep the file in mutex lock until modifications are done so that readers can have no access to the files. Once all modifications are done by all writers the lock can be released. We even decrement the active_writers to give chance to other writers who want to modify the data in the file.

Add a comment
Know the answer?
Add Answer to:
In the class we mentioned briefly the readers-writers problem with writers priority. The problem can be solved in guard...
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
  • 4. (20 points) In the class we mentioned briefly the readers-writers problem with writers priority. The problem can...

    4. (20 points) In the class we mentioned briefly the readers-writers problem with writers priority. The problem can be solved in guarded commands as follows: void writer) void reader --owriters when writers0 readers++i when (readers0)&&(active writers0) active writers++ //read //write [readers--1 [writers-- active writers-- Here writers represents the number of threads that are either writing or waiting to write. The variable active_writers represents the number of threads (0 or1) that are currently writing. Implement the solution using either POSIX threads...

  • Process Synchronization Assignment: Readers-Writers Problem . Consider readers and writers share a bounded array. ii. Writers...

    Process Synchronization Assignment: Readers-Writers Problem . Consider readers and writers share a bounded array. ii. Writers write an integer on the array. iii. Readers read and display contents of the array. iv. Writers will not be allowed to write if there is a reader reading the array. v. Only one writer can access the array at a time. But many readers can access the array at the same time. vi. All readers are blocked if there is a writer writing...

  • For the readers & writers problem we discussed the solution to the readers-priority variant (where readers...

    For the readers & writers problem we discussed the solution to the readers-priority variant (where readers can keep entering the DB provided another reader is already there, and a writer must wait for all readers to exit on their own). What was the problem we discussed with this solution?

  • pleasw answer as soon as possible . this is for my exam practice . please read...

    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 shared file. The following variables are shared among all processes: int readCounter; semaphore mutex, writeLock; Reader and writer processes are given in the following C++-like pseudo programs: Reader Process // Non-Critical Section P(mutex); Writer Process // Non-Critical...

  • 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...

  • Problem 2. In this problem we consider the question of whether a small value of the...

    Problem 2. In this problem we consider the question of whether a small value of the residual kAz − bk means that z is a good approximation to the solution x of the linear system Ax = b. We showed in class that, kx − zk kxk ≤ kAkkA −1 k kAz − bk kbk . which implies that if the condition number kAkkA−1k of A is small, a small relative residual implies a small relative error in the solution....

  • Use Java language to write exercise 4.20 pid manager Exercise 3.20 An operating system’s pid manager...

    Use Java language to write exercise 4.20 pid manager Exercise 3.20 An operating system’s pid manager is responsible for managing process identifiers. When a process is first created, it is assigned a unique pid by the pid manager. The pid is returned to the pid manager when the process completes execution, and the manager may later reassign this pid. Process identifiers must be unique. No two active processes may have the same pid. Use the following constants to identify the...

  • Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an...

    Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an order at a fast-food burger joint. This class will be used in Part B, when we work with a list of orders. As vou work through this part and Part B, draw a UML diagram of each class in using the UML drawing tool 1) Create a new Lab5TestProject project in Netbeans, right-click on the lab5testproject package and select New>Java Class 2) Call your...

  • Needs Help with Java programming language For this assignment, you need to write a simulation program...

    Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...

  • Problem 3 (List Implementation) (35 points): Write a method in the DoublyLList class that deletes the...

    Problem 3 (List Implementation) (35 points): Write a method in the DoublyLList class that deletes the first item containing a given value from a doubly linked list. The header of the method is as follows: public boolean removeValue(T aValue) where T is the general type of the objects in the list and the methods returns true if such an item is found and deleted. Include testing of the method in a main method of the DoublyLList class. ------------------------------------------------------------------------------------- /** A...

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