Invariant Based Methodology

Slides:



Advertisements
Similar presentations
CIS 720 Lecture 2. Concurrency …shared variable declaration…. …shared variable initialization… co P 1 // P 2 // P 3 // P 4 oc Execution of P 1 … P 4 starts.
Advertisements

Producer-Consumer One common situation: Producers and consumers communicate via a buffer.
1 Semaphores and Monitors CIS450 Winter 2003 Professor Jinhua Guo.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 13: October 12, 2010 Instructor: Bhuvan Urgaonkar.
Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 91 Today’s class Mutual exclusion and synchronization 
Synchronization CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
6/16/2015 Chapter Eight Process Synchronisation. Index Objectives Concurrent processes and Asynchronous concurrent processes Process synchronisation Mutual.
1 Semaphores Special variable called a semaphore is used for signaling If a process is waiting for a signal, it is suspended until that signal is sent.
Language Support for Concurrency. 2 Common programming errors Process i P(S) CS P(S) Process j V(S) CS V(S) Process k P(S) CS.
CS470 Lab 4 TA Notes. Objective Simulate the activities of a producer and consumer – Page 326 Use thread synchronization to solve the producer-consumer.
Classical Synchronization Problems. Paradigms for Threads to Share Data We’ve looked at critical sections –Really, a form of locking –When one thread.
IPC and Classical Synchronization Problems
CS444/CS544 Operating Systems Classic Synchronization Problems 3/5/2007 Prof. Searleman
Classical Synchronization Problems. Announcements CS 414 grades and solutions available in CMS soon. –Average 74.3 –High of 95. –Score out of 100 pts.
1 Chapter 5 Concurrency. 2 Concurrency 3 4 Mutual Exclusion: Hardware Support Test and Set Instruction boolean testset (int *i) { if (*i == 0) { *i.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Chapter 6(b): Synchronization.
Critical Problem Revisit. Critical Sections Mutual exclusion Only one process can be in the critical section at a time Without mutual exclusion, results.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 14: October 14, 2010 Instructor: Bhuvan Urgaonkar.
Synchronization II: CPE Operating Systems
4061 Session 21 (4/3). Today Thread Synchronization –Condition Variables –Monitors –Read-Write Locks.
Synchronization Methods in Message Passing Model.
Lecture 6: Synchronization (II) – Semaphores and Monitors
CSE 451: Operating Systems Winter 2012 Semaphores and Monitors Mark Zbikowski Gary Kimura.
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Synchronization.
SPL/2010 Guarded Methods and Waiting 1. SPL/2010 Reminder! ● Concurrency problem: asynchronous modifications to object states lead to failure of thread.
Concurrency in Shared Memory Systems Synchronization and Mutual Exclusion.
1 Semaphores n Semaphores  Issues addressed:  1. Problems with busy-waiting  2. Definition of a semaphore: init(s), P(s) and V(s) - invariant  3. Examples.
CIS 720 Lecture 5. Techniques to avoid interference Disjoint variables –If the write set of each process is disjoint from the read and write set of other.
1 Previous Lecture Overview  semaphores provide the first high-level synchronization abstraction that is possible to implement efficiently in OS. This.
Producer-Consumer Problem David Monismith cs550 Operating Systems.
Semaphores Chapter 6. Semaphores are a simple, but successful and widely used, construct.
Readers/Writers Problem  Multiple processes wanting to read an item, and one or more needing to write (Think of airline reservations…)  Rather than enforce.
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
Operating Systems NWEN 301 Lecture 6 More Concurrency.
CSE 451: Operating Systems Spring 2006 Module 8 Semaphores and Monitors John Zahorjan Allen Center 534.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Scuola Superiore Sant’Anna A design Methodology for Concurrent programs Giuseppe Lipari.
Classical Synchronization Problems
The Critical-Section Problem (Two-Process Solution)
An object-based synchronization mechanism.
ITEC452 Distributed Computing Lecture 5 Program Correctness
Process Synchronization
CIS 720 Mutual Exclusion 2.
CSE 451: Operating Systems Winter Module 8 Semaphores and Monitors
Semaphores Chapter 6.
CSE 451: Operating Systems Autumn Lecture 8 Semaphores and Monitors
CSE 451: Operating Systems Winter Module 7 Semaphores and Monitors
CSE 451: Operating Systems Winter Module 7 Semaphores and Monitors
Chapter 7: Synchronization Examples
CIS 720 Lecture 5.
CSE 451: Operating Systems Winter Module 7 Semaphores and Monitors
, Part II Process Synchronization
Other Synchrnization Problems
CIS 720 Lecture 6.
Wait-free synchronization
CIS 720 Lecture 4.
CIS 720 Lecture 4.
CIS 720 Lecture 3.
CIS 720 Lecture 3.
' · · ,.-.., '' !'",. -,..._ ·-.·-...;.· -
CIS 720 Lecture 5.
CIS 720 Lecture 2.
CIS 720 Lecture 4.
CIS 720 Lecture 4.
CIS 720 Lecture 2.
CIS 720 Mutual Exclusion 2.
Passing the Baton Technique
CIS 720 Lecture 4.
Presentation transcript:

Invariant Based Methodology CIS 720 Invariant Based Methodology

Producer/consumer problem do true  do true  produce pdata buf = pdata cdata = buf; consume cdata od od oc

Producer/consumer problem in1 = out1 = in2 = out2 = 0; co Producer: Consumer: do true  {in1=out1} do true  {in2=out2} produce pdata in1 = in1 + 1 in2 = in2 + 1 buf = pdata {in1 = out1+1} cdata = buf {in2 = out2+1} out1 = out1 + 1 out2 = out2 + 1 {in1=out1} consume cdata {in2 = out2} od od oc Invariant:

Producer/consumer problem do true  do true  produce pdata <await(in1 <=out2)  in1 = in1 + 1> <await(in2 < out1) in2 = in2 + 1> buf = pdata cdata = buf <out1 = out1 + 1> <out2 = out2 + 1> consume cdata od od oc Invariant: (in1 <= out2 + 1) /\ (in2 <= out1)

Producer/consumer problem do true  do true  produce pdata <await(empty > 0)  empty= empty -1> <await(full > 0)  full = full -1 > buf = pdata cdata = buf <full = full + 1> <empty = empty + 1> consume cdata od od oc Invariant: (in1 <= out2 + 1) /\ (in2 <= out1) empty = out2 + 1 in1 full = out1 – in2

Producer/consumer problem do true  do true  produce pdata P(empty) P(full) buf = pdata cdata = buf V(full) V(empty) consume cdata od od oc Invariant: (in1 <= out2 + 1) /\ (in2 <= out1) empty = out2 + 1 in1 full = out1 – in2

Producer/consumer problem in1 = out1 = in2 = out2 = 0; co Producer: Consumer1: Consumer2: do true  do true  do true  produce pdata in1 = in1 + 1 in2 = in2 + 1 in3 = in3 + 1 buf = pdata cdata = buf cdata = buf out1 = out1 + 1 out2 = out2 + 1 out3 = out3 + 1 consume cdata consume cdata od od od oc Invariant:

Readers/writers problem A reader and a writer cannot read and write respectively at the same time. Two writers cannot write at the same time.

Readers/writers problem co Reader[i]: Writer[j]: do true  do true  P(rw) P(rw) read write V(rw) V(rw) od od oc

Readers/writers problem co Reader[i]: Writer: do true  do true  nr = nr + 1 P(rw) if nr == 1  P(rw) fi write read nr = nr - 1 if (nr =0) V(rw) fi V(rw) od od oc

Readers/writers problem co Reader[i]: Writer: do true  do true  nr=nr+1 nw = nw + 1 read write nr = nr - 1 nw = nw - 1 od od oc

Readers/writers problem co Reader[i]: Writer: do true  do true  nr=nr+1 nw = nw + 1 read write nr = nr - 1 nw = nw - 1 od od oc BAD = (nr > 0 /\ nw > 0 ) \/ nw > 1 Invariant: not (BAD) (nr = 0 \/ nw = 0) /\ nw <= 1

Readers/writers problem co Reader[i]: Writer: do true  do true  inr = inr + 1 inw = inw + 1 read write outr = outr + 1 outw = outw + 1 od od oc

Readers/writers problem co Reader[i]: Writer: do true  do true  inr = inr + 1 inw = inw + 1 read write outr = outr + 1 outw = outw + 1 od od oc BAD = Invariant:

Technique of Passing the baton Solution may contain statements F1 : <S> F2 : < await (Bj)  Sj > Introduce the following semaphores e : for controlling access to evaluate the conditions bj : for each guard Bj

Introduce a new counter dj for each guard Bj Replace as follows: F1: P(e) Sj SIGNAL

Readers/writers problem co Reader[i]: Writer: do true  do true  <await(nw = 0)  nr=nr+1> <await(nw=0 /\ nr = 0)  nw = nw + 1> read write <nr = nr – 1> <nw = nw – 1> od od oc

Readers/writers problem co Reader[i]: do true  <await(nw = 0)  nr=nr+1> read <nr = nr – 1> od oc

Readers/writers problem co Writer: do true  <await(nw=0 /\ nr = 0)  nw = nw + 1> write <nw = nw – 1> od oc

SIGNAL if (nw = 0 and dr > 0)  dr = dr – 1; V(r) elseif (nw = 0 and nr = 0 and dw > 0)  dw = dw – 1; V(w) else V(e)

co Reader[i]: Writer: do true  do true  P(e) P(e) if (nw > 0) dr++; V(e); P(r) fi if (nw=0 /\ nr = 0)  dw++; V(e); P(w) fi nr++; nw++; SIGNAL SIGNAL read write nr--; nw-- SIGNAL SIGNAL od od oc SIGNAL if (nw = 0 and dr > 0)  dr = dr – 1; V(r) elseif (nw = 0 and nr = 0 and dw > 0)  dw = dw – 1; V(w) else V(e)

Weak Reader preference If a reader A is reading and a reader B and a writer C is waiting then B is given preference.

Strong Reader preference If a reader B and a writer C is waiting then B is given preference.

Strong Writer preference If a reader B and a writer C is waiting then C is given preference. SIGNAL: If nw = 0 /\ dr > 0 /\ dw = 0  dr = dr – 1; V(r) [] nr = 0 /\ nw = 0 /\ dw > 0  dw = dw – 1; V(w); [] else -> V(e) fi