Category: 

What Is the Readers-Writers Problem?

Article Details
  • Written By: Mary McMahon
  • Edited By: Shereen Skola
  • Last Modified Date: 06 October 2014
  • Copyright Protected:
    2003-2014
    Conjecture Corporation
  • Print this Article
Free Widgets for your Site/Blog
Sharks hunt by sensing electromagnetic fields produced by their prey.  more...

October 24 ,  1929 :  The Black Thursday crash in the US stock market took place.  more...

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.

Ad

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.

Ad

More from Wisegeek

You might also Like

Discuss this Article

Post your comments

Post Anonymously

Login

username
password
forgot password?

Register

username
password
confirm
email