Learn something new every day More Info... by email
The "readers-writers problem" is a programming dilemma created when multiple readers and writers need access to the same resource. If they were all allowed access at once, problems like overwrites, incomplete information, and other issues might arise. Therefore, programmers may restrict access to control which processing threads see the resource and when, considering the needs of the system and the users. There are several ways to address the readers-writers problem. One of the most common solutions involves the use of semaphores to flag the status and control access.
From one perspective, any number of readers could safely access a resource because they are not making changes to the content. Once a writer enters the equation, the situation becomes more complicated. If a thread is writing while other threads are reading, the readers may not get correct information. They could receive only part of the change, or might see the outdated information and think it’s accurate.
More than one writer could also create a problem. Simultaneous changes to the same content might overwrite it and create other errors. Under the readers-writers problem, programmers must decide whether readers or writers have priority, and how to handle access. Readers or writers could be assigned priority, or the system could assign access on a first come, first serve basis. This third solution may prevent long waits, but could come with problems of its own.
In a solution where readers have priority, the system assumes that any reader asking for access should be allowed in first, when access becomes available. This means that any writers that want to access the resource could need to wait. Conversely, the system might assume that because writers need to make changes that might affect readers, they should be given priority under the readers-writers problem. When a reader is done with a resource, a writer could jump in to make a change. This applies not just to user actions like trying to save a document, but to internal processes inside the computer that keep the system running.
Another option allows the readers-writers problem to balance the needs of both parties, allowing each processing thread access as it arrives. This prevents writers from making changes that override each other or confuse readers, without leaving readers waiting, or forcing writers to hold while readers finish. Such priorities can be built into a software program or memory access control in a computer. Users may be able to make changes if they are comfortable with programming and the system allows it.
One of our editors will review your suggestion and make changes if warranted. Note that depending on the number of suggestions we receive, this can take anywhere from a few hours to a few days. Thank you for helping to improve wiseGEEK!