Concurrent Control with “Readers” and “Writers”

1 / 18

# Concurrent Control with “Readers” and “Writers” - PowerPoint PPT Presentation

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

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about 'Concurrent Control with “Readers” and “Writers”' - polly

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### Concurrent Control with “Readers” and “Writers”

Sagnik Bhattacharya

Siddharth Dalal

Sequential Programs
• Terminating
• Number of possible execution paths finite
• Constructions like if-then-else, while are strictly defined
• Mathematical tools (though complicated) exist.
Concurrent Programs
• Possibly non-terminating
• Infinite number of possible execution paths
• Synchronization
• Scheduling
• Prevention of starvation
• Lack of formal tools to deal with concurrency

Writer

Critical Section

Writer

Writer

Writer

Critical Section

Writer

Writer

YES!

Writer

Critical Section

Writer

Writer

NO!

Writer

Critical Section

Writer

Writer

NO!

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;
Waiting readers have higher priority.Problem 1

GLOBALS

mutex, w : semaphore := 1; // Mutual exclusion semaphores

Problem 1

P(mutex);

V(mutex);

CRITICAL REGION

P(mutex);

V(mutex);

WRITER

P(w);

CRITICAL REGION

V(w);

Waiting writers have higher priorityProblem 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;

Problem 2

P(mutex3);

P(r);

P(mutex1);

if (readcount is 1) then P(w);

V(mutex1);

V(r);

V(mutex3);

CRITICAL REGION

P(mutex1);

if (readcount is 0) then V(w);

V(mutex1);

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);

Does this guarantee FIFO order?
• NO!!
• For Writers?
• NO!!
To achieve FIFO order…
• Make P and V operations more powerful
• Use array of semaphores
To achieve prioritized order…
• Inter-process communication
• Complicated
• Shared memory