As a result, the third readers-writers problem is occasionally presented, which adds the restriction that no thread must be allowed to hunger; that is, the action of gaining a lock on the shared data must always end in a defined period of time. A solution that is fair to both readers and writers may be as follows: every writer gets a chance in turn to use the data. When they all try to write at the same time, none will be permitted until one releases the lock.
This is known as the "readers-writers dilemma" in operating systems. A single set of parameters is shared by several processes. When a writer is ready, it goes to work. Only one writer may work at any given time. No other process can read what a process is writing. When that writer finishes, another takes its place and so on.
The writer-reader problem arises when there are multiple sets of parameters (multiple copies of the same program). Many operating systems solve this problem by using threads. A thread is a sequence of instructions that can run independently of others. Sometimes threads are referred to as processes but they do not have to be. Each thread has its own memory space and can write and read whatever it wants. Threads can also share memory spaces or even become joined together into a single process. Linux and Windows are two common operating systems that use threads to solve the writer-reader problem.
There you have it! The writer-reader problem arises when multiple copies of a program want to use the same data at the same time. Solutions include threads and locks.
The readers-writers problem relates to an object such as a file that is shared between multiple processes. Some of these processes are readers, i.e. they only want to read the data from the object, and some of the processes are writers, i.e. they want to write into the object. Without proper synchronization, a reader may prematurely return data it has not yet fully processed, or miss changes made by a writer.
In computer science, the readers-writers problem is the simplest form of concurrency control. It can be stated as follows: given an object on which several processes may read concurrently and several more may write concurrently, determine if any process could corrupt the object's state.
It is important to note that the readers-writers problem does not specify how the processes communicate with each other. In other words, the problem assumes that the processes have no way of knowing who else is reading or writing to the object at any given time. This means that there is no way for them to cooperate in order to avoid conflict. For example, a first process that wants to write to the object might do so immediately after reading data from it. However, a second process that wants to read the object later could see the first process' change even though its own request was denied because the second process had not yet finished reading.
There are many solutions to this problem. One solution is to use a lock mechanism when accessing the object.
If there are writers waiting to alter the resource and new readers arrive all the time, the writers will never be allowed access as long as there is at least one active reader. Give emphasis to authors; readers may go hungry here.
Starvation can also occur if all the readers are waiting for their turn to use the resource but none of them has yet. In this case, too, no writer can make any changes to the resource because they all want it to be as fresh as possible when they read it. This example shows that starvation can also happen when everyone wants the same thing at the same time.
Finally, starvation can also occur if some readers are waiting for their turn while others are not. For example, let's say that there are 10 readers and 5 writers. Readers 1 through 5 are waiting for their turn, while readers 6 through 10 are not. If all the writers try to give priority to readers 1 through 5 first, then readers 6 through 10 will never get their chance to use the resource!
In conclusion, starvation can occur whenever there are multiple readers or writers who want to use or alter a shared resource simultaneously.
Operating System MCAO (Computer Science). The readers-writers dilemma is related to an item that is shared by numerous processes, such as a file. Some of these processes are readers, meaning they just want to read data from the object, while others are writers, meaning they want to write into the object. To ensure consistency, every writer must acquire a lock on the object before modifying it. This prevents multiple writers from executing simultaneously.
There are two types of locks: shared and exclusive. A shared lock can be acquired by any number of processes, whereas an exclusive lock can be obtained by only one process at a time. Shared locks are necessary because not all parts of a program should be writing to the same resource at once. For example, if a database were used as an application resource, some programs might need only read access to the data, while other programs or modules could benefit from being able to update the data too. Using shared locks ensures that multiple programs do not attempt to modify the resource simultaneously, thereby avoiding data corruption.
Exclusive locks are needed when making a change is more important than maintaining consistency. For example, if a process was in the middle of saving data to a file when another process tried to make an identical save request, the second process would have to wait for the first process to finish before doing so.