[Typical operating system problems] Analysis of reader Problems

Source: Internet
Author: User

Philosophers dining problems are very useful in modeling processes such as competition for mutually exclusive access to limited resources (such as I/O devices. Another famous issue is the reader-writer issue (Courtois ).
Et al., 1971). It creates a model for database access. For example, imagine an airplane ticket booking system in which many competing processes attempt to read and write data. Multiple processes can read the database at the same time
But if a process is updating (writing) The database, all other processes cannot access the database, even if the read operation fails. The question here is how to program readers and writers? Figure 2-47
A solution is provided.

In this solution, the first reader executes the down operation on the semaphore dB. Then the reader only increments the RC counter. When the reader leaves, they decrease the counter, and the last reader executes up on the semaphore, so that a blocked writer (if any) can access the database.

In this solution, there is a condition that requires annotation. Assume that one reader is using the database, and the other reader is coming. At the same time, there are no problems for two readers, and the second reader is allowed to enter. This is also allowed if the third and more readers come.

Now, let's assume that a writer is coming. Because the writer's access is exclusive, the writer cannot access the database and can only be suspended. As long as there is another reader in the activity, it will allow subsequent readers to come in. This policy
The result is that if a stable reader stream exists, these readers will be allowed to enter after arrival. The writer is always suspended until there are no readers. For new readers, for example, every two seconds
Every reader spends five seconds to complete his/her work, so the writer will never have a chance.

To avoid this situation, you can change it a bit.ProgramWriting: When a reader arrives and a writer is waiting, the reader is suspended after the writer, rather than allowing access immediately. In this way
If a writer has a working reader when he arrives, the writer only needs to wait for the reader to complete, instead of waiting for the reader to come later. The disadvantage of this solution is that the concurrency and efficiency are low.
Courtois and others provide a writer-first solution.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.