1 / 18

Concurrent Control with “Readers” and “Writers”

Concurrent Control with “Readers” and “Writers”. Sagnik Bhattacharya Siddharth Dalal. Sequential Programs. Terminating Single thread or process Number of possible execution paths finite Constructions like if-then-else, while are strictly defined

polly
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” Sagnik Bhattacharya Siddharth Dalal

  2. Sequential Programs • Terminating • Single thread or process • Number of possible execution paths finite • Constructions like if-then-else, while are strictly defined • Mathematical tools (though complicated) exist.

  3. Concurrent Programs • Possibly non-terminating • Infinite number of possible execution paths • Synchronization • Scheduling • Prevention of starvation • Lack of formal tools to deal with concurrency

  4. Readers and Writers Problem Reader Writer Critical Section Writer Reader Writer Reader

  5. Readers and Writers Problem Reader Writer Critical Section Writer Reader Writer Reader YES!

  6. Readers and Writers Problem Reader Writer Critical Section Writer Reader Writer Reader NO!

  7. Readers and Writers Problem Reader Writer Critical Section Writer Reader Writer Reader NO!

  8. The P and V operations • Sometimes referred to as wait and signal • P(S) : • while S < 0 do no-op; • S := S - 1; • V(S) : • S := S + 1;

  9. Waiting readers have higher priority. Problem 1 GLOBALS mutex, w : semaphore := 1; // Mutual exclusion semaphores readcount : integer   := 0;

  10. Problem 1 READER P(mutex); readcount++; if (readcount=1) then P(w); V(mutex); CRITICAL REGION P(mutex); readcount--; if (readcount=0) then V(w);   V(mutex); WRITER P(w); CRITICAL REGION V(w);

  11. For Readers? NO!! For Writers? NO!! Does this guarantee FIFO order?

  12. Waiting writers have higher priority Problem 2 GLOBALS mutex1 : semaphore := 1; // all semaphores here are mutual exclusionmutex2 : semaphore := 1;mutex3 : semaphore := 1;w     : semaphore := 1;r      : semaphore := 1;readcount, writecount : integer := 0;

  13. Problem 2 READER P(mutex3); P(r); P(mutex1); readcount++; if (readcount is 1) then P(w); V(mutex1); V(r); V(mutex3); CRITICAL REGION P(mutex1); readcount--; if (readcount is 0) then V(w); V(mutex1);

  14. Problem 2 WRITER P(mutex2); writecount++; if (writecount is 1) then P(r); V(mutex2); P(w); CRITICAL REGION V(w); P(mutex2); writecount--; if (writecount is 0) then V(r); V(mutex2);

  15. Does this guarantee FIFO order? • For Readers? • NO!! • For Writers? • NO!!

  16. To achieve FIFO order… • Make P and V operations more powerful • Use array of semaphores

  17. To achieve prioritized order… • Inter-process communication • Complicated • Shared memory • Readers and Writers problem

  18. Philosophical question • Should we build safety critical concurrent systems?

More Related