1 / 18

Concurrent Control with "Readers" and "Writers"

Concurrent Control with "Readers" and "Writers". P. J. Courtois, F. Heymans and D. L. Parnas Communication of the ACM, 14, 10 (Oct. 1971) Presenters: Prashant Agrawal Vineet Bansal. Main Paper. Critical section is a part of a program where the shared memory is accessed

amory
Télécharger la présentation

Concurrent Control with "Readers" and "Writers"

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Concurrent Control with "Readers" and "Writers" P. J. Courtois, F. Heymans and D. L. Parnas Communication of the ACM, 14, 10 (Oct. 1971) Presenters: Prashant Agrawal Vineet Bansal

  2. Main Paper • Critical section is a part of a program where the shared memory is accessed • Semaphores are used extensively to solve concurrent access problems • Readers/Writers problem is a typical example of concurrent access to shared data

  3. Main Paper (cont) • Readers only want to read the shared data • Writers want to modify the shared data • Exclusive write semantics is enforced • Two solutions have been presented • First solution gives priority to the readers • Second solution gives priority to the writers

  4. Main Paper (cont) • First Solution • The first reader who wants entry must obtain a “main” semaphore, seen by all processes. • While at least one reader is in the critical section, other readers are allowed free entry and exit. • The last reader to exit releases the semaphore and allows entry to a waiting writer. • Drawback: May block writers for a long time

  5. Main Paper (cont) • Second Solution • Readers block while writers gain immediate access to the data. • The first writer to capture access to the shared resource blocks other readers from entering the critical section. • Drawback: May block readers for a long time

  6. Concurrent Reading and WritingL. Lamport (1977) • In true concurrent environments, serializing accesses may result in a considerable overhead. • “Versions” of data v[i] = v1[i]…vm[i] • Reading and writing v is not atomic. • Value obtained v[k,l] contains “traces” of versions v[i]…v[im] where k = minimum(i1, .. , im). l = maximum(i1, .. , im). • The read operation obtains a consistent version v[k] of v if k = l.

  7. Concurrent Reading and Writing Theorem • Assume that i  j implies v[i]v[j] • If v is always written from right to left, then a read from left to right obtains a value v[k,l] v[l]. • If v is always written from left to right, then a read from right to left obtains a value v[k,l] v[l] • Writing data elements in one order and reading them in the opposite order allows us to solve the Readers/Writers Problem without assuming mutual exclusion of shared data. • Useful in cases where a reader repeats the read operation if it obtains an incorrect result due to a concurrent write operation.

  8. Concurrent Reading and Writing • Application to Reader/Writer Problem: • We maintain two versions of the data: v1 and v2. • The writer increments v1 before it writes the data and it increments v2 after writing the data. • The reader reads v2 before reading the data and v1 after reading it. In cases where these values are different, it attempts the read operation again. • For the scheme to work, v1 must be written left to right and read right to left, and v2 must be written right to left and read left to right.

  9. Concurrent Reading While WritingGary L. Peterson (1983) • Discusses various algorithms to read shared data while another process is modifying that data • More time efficient algorithms are used multiple copies of the shared data are required • Six algorithms have been presented with various degrees of time efficiency

  10. Concurrent Reading While Writing • n readers and one writer access shared data asynchronously • Shared data cannot be read or written atomically • Main Algorithm • the readers and writers are made wait-free at the cost of n+2 buffers

  11. Concurrent Reading While Writing • Writer writes to buff1 • Detects any overlapping reads and makes copies for those readers and places them in buff2 • Reader reads the value from buff1 and then from buff2 • Checks if buff2 is a copy of buff1 and if so it uses that value. • If buff2 and buff1 differ then it uses shared variable to determine if buff1 is correct and then uses its value.

  12. The Non-Blocking Write Protocol NBWH. Kopetz and J. Reisinger(1993) • Two solutions for the problem of multiple readers and a single writer for a hard-real time system • Protocols use read-and-check method for the readers

  13. The Non-Blocking Write Protocol NBW • First Solution: • Control field CCF that is initialized to zero • Writer increments the CCF by 1 and then writes the data • CCF is again incremented by 1 • Reader reads the value of CCF • Reads the data and again reads the value of CCF • If the two values differ or if the first value is odd, it concludes that an overlapping write took place and it restarts the process.

  14. The Non-Blocking Write Protocol NBW • Drawbacks of first protocol: • Not to handle tasks that do have any laxity for read-retries. • Laxity is the time difference between the maximum amount of execution time required by the task and its deadline. • If a read call takes an appreciable portion of execution time then executing read multiple times makes this protocol inefficient. • Second protocol • Uses buffers to store multiple copies of the data • Another control variable bcnt that is used to indicate the number of buffers reserved for the data

  15. A Three-Slot Asynchronous Reader/WriterJ. Chen and A. Burns (1997) • Single Reader/Single Writer problem for a real-time system • In real-time systems • Response time of the system to various events is critical. • Processes should not block • Mechanisms are fully asynchronous and allows the reader and the writer to access the shared data in a loop-free and wait-free manner

  16. Three-Slot Asynchronous Reader/Writer • Main Algorithm • Requires 3 buffers slots • writer chooses from two buffers when it wants to write and leaves 1 slot from which the reader can read • Control variable LATEST is used to indicate the buffer slot that has the latest version of the data • Control variable READING is used to indicate the buffer slot that the reader is reading from

  17. Three-Slot Asynchronous Reader/Writer • The READING variable can be updated by either the writer or the reader • The READING variable is also used to indicate the state of the reader. • A zero value in the control variable of the reader indicates that it is preparing to read the data. Any non-zero value indicates that the reader is reading the data or is inactive. • The reader makes READING zero, reads LATEST and copies to READING • If a writer after completing the update of the shared data discovers READING = 0 then it writes the position of the buffer having the latest copy of the data to READING.

  18. Three-Slot Asynchronous Reader/Writer • Writer use an atomic read-and-write instruction ("compare-and-swap" operation). • Before the reader moves the number of the buffer it is reading to READER, it checks to see if any writer has updated READING and if so then it uses the buffer number written by the writer

More Related