CIS 720 Lecture 5.

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
CS5270 Lecture 31 Uppaal, and Scheduling, and Resource Access Protocols CS 5270 Lecture 3.
Program correctness The State-transition model A global state S  s 0 x s 1 x … x s m {s k = local state of process k} S0  S1  S2  … Each state transition.
Mutual Exclusion By Shiran Mizrahi. Critical Section class Counter { private int value = 1; //counter starts at one public Counter(int c) { //constructor.
Concurrent Programming Problems OS Spring Concurrency pros and cons Concurrency is good for users –One of the reasons for multiprogramming Working.
1 Chapter 2 Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2007 Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld.
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
Multiprocessor Synchronization Algorithms ( ) Lecturer: Danny Hendler The Mutual Exclusion problem.
1 Operating Systems, 122 Practical Session 5, Synchronization 1.
Multithreaded Programming ECEN5043 Software Engineering of Multiprogram Systems University of Colorado Lectures 5 & 6.
Chapter 3 The Critical Section Problem
CIS 720 Mutual Exclusion. Critical Section problem Process i do (true) entry protocol; critical section; exit protocol; non-critical section od.
Parallel Processing (CS526) Spring 2012(Week 6).  A parallel algorithm is a group of partitioned tasks that work with each other to solve a large problem.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Assignment – no class Wednesday All: watch the Google Techtalk “Getting C++ Threads Right” by Hans Boehm at the following link in place of Wednesday’s.
University of Pennsylvania 9/19/00CSE 3801 Concurrent Processes CSE 380 Lecture Note 4 Insup Lee.
Synchronization (other solutions …). Announcements Assignment 2 is graded Project 1 is due today.
1 Thread Synchronization: Too Much Milk. 2 Implementing Critical Sections in Software Hard The following example will demonstrate the difficulty of providing.
Representing distributed algorithms Why do we need these? Don’t we already know a lot about programming? Well, you need to capture the notions of atomicity,
The Critical Section Problem
28/10/1999POS-A1 The Synchronization Problem Synchronization problems occur because –multiple processes or threads want to share data; –the executions.
Concurrency. A process is a program executing on a virtual computer Processor speed and multiplexing of shared resources are ignored Order of thread execution.
The Complexity of Distributed Algorithms. Common measures Space complexity How much space is needed per process to run an algorithm? (measured in terms.
Mutual Exclusion Using Atomic Registers Lecturer: Netanel Dahan Instructor: Prof. Yehuda Afek B.Sc. Seminar on Distributed Computation Tel-Aviv University.
Program correctness The State-transition model The set of global states = so x s1 x … x sm {sk is the set of local states of process k} S0 ---> S1 --->
Program correctness The State-transition model A global states S  s 0 x s 1 x … x s m {s k = set of local states of process k} S0  S1  S2  Each state.
Hwajung Lee. The State-transition model The set of global states = s 0 x s 1 x … x s m {s k is the set of local states of process k} S0  S1  S2  Each.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 11: October 5, 2010 Instructor: Bhuvan Urgaonkar.
Hwajung Lee. The State-transition model The set of global states = s 0 x s 1 x … x s m {s k is the set of local states of process k} S0  S1  S2  Each.
1 Lecture 8: Concurrency: Mutual Exclusion and Synchronization Advanced Operating System Fall 2012.
Hwajung Lee. Well, you need to capture the notions of atomicity, non-determinism, fairness etc. These concepts are not built into languages like JAVA,
Hwajung Lee. Why do we need these? Don’t we already know a lot about programming? Well, you need to capture the notions of atomicity, non-determinism,
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.
Program Correctness. The designer of a distributed system has the responsibility of certifying the correctness of the system before users start using.
Presented by: Belgi Amir Seminar in Distributed Algorithms Designing correct concurrent algorithms Spring 2013.
1 Critical Section Problem CIS 450 Winter 2003 Professor Jinhua Guo.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Synchronization Questions answered in this lecture: Why is synchronization necessary? What are race conditions, critical sections, and atomic operations?
Bakery Algorithm - Proof
CSE 120 Principles of Operating
Model and complexity Many measures Space complexity Time complexity
Hwajung Lee ITEC452 Distributed Computing Lecture 8 Representing Distributed Algorithms.
Designing Parallel Algorithms (Synchronization)
Atomicity, Non-determinism, Fairness
ITEC452 Distributed Computing Lecture 5 Program Correctness
COP 4600 Operating Systems Spring 2011
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Critical Sections User Software Solutions Dekker’s Algorithm
CIS 720 Mutual Exclusion 2.
Lecture 2 Part 2 Process Synchronization
Practical Session 5, Synchronization
Mutual Exclusion CS p0 CS p1 p2 CS CS p3.
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Lecture 21 Syed Mansoor Sarwar
Physical clock synchronization
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
ITEC452 Distributed Computing Lecture 7 Mutual Exclusion
CIS 720 Lecture 5.
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
CIS 720 Lecture 6.
Lecture 19: Coherence and Synchronization
CIS 720 Lecture 3.
CIS 720 Lecture 3.
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Process/Thread Synchronization (Part 2)
CIS 720 Mutual Exclusion 2.
Syllabus 1. Introduction - History; Views; Concepts; Structure
Don Porter Portions courtesy Emmett Witchel
Presentation transcript:

CIS 720 Lecture 5

Safety and liveness properties A safety property states that something bad will not happen A liveness property states that something good will eventually happen

Proving safety property BAD= predicate characterizing the bad property GOOD = not BAD Prove that GOOD is an invariant

Liveness property A statement is eligible if it is the next action that could be executed Scheduling policy determines the next statement to be executed

Weak Fairness: A scheduling policy is weak fair if x = true co while (x)  skip [] x = false oc x = 0; y = 0 co while (x = 0)  y = y + 1 [] await ( y > 5)  x = 1 oc Unconditional fairness: A scheduling policy is unconditionally fair if every unconditional atomic action (one which does not have a guard) that is eligible is executed eventually. Weak Fairness: A scheduling policy is weak fair if It is unconditionally fair Every conditional action that is eligible is eventually executed assuming that its guard becomes true and remains true.

Strong Fairness: A scheduling policy is strong fair if It is unconditionally fair Every conditional action that is eligible is eventually executed assuming that its guard becomes true and becomes true infinitely often x = 0; y = 0 co while (x = 0)  y = y + 1 [] await ( y is even)  x = 1 oc

Critical Section problem Process i do (true) entry protocol; critical section; exit protocol; non-critical section od

Correctness Mutual exclusion: at most one process at a time is executing its critical section Absence of deadlock: If two or more processes are trying to enter their critical section, at least one will succeed Absence of unnecessary delay: If a process is trying to enter its critical section and the other processes are executing their non-critical sections or have terminated then the first process is not prevented from entering its critical section. Eventual entry: A process that is attempting to enter its critical section will eventually succeed.

Invariant based approach { in1 = false; in2 = false } CS1 CS2 do (true) do (true)  entry protocol; entry protocol; in1 = true in2 = true critical section critical section exit protocol; exit protocol; in1 = false in2 = false non-critical section non-critical section od { I /\¬ in1} { I /\¬ in2} { I /\ in1} { I /\ in2} { I /\¬ in1} { I /\¬ in2} BAD = ¬ in1 /\ ¬ in2 I = ¬ BAD = ¬ (in1 /\ in2) = ¬ in1 \/ ¬ in2

Invariant based approach CS1 CS2 do (true) do (true)  in1 = true in2 = true critical section critical section in1 = false in2 = false non-critical section non-critical section od { I /\¬ in1} <await (¬ in2)  <await (¬ in1)  > > { I} { I /\ ¬ in1} Weakest precondition wp(A, action) {wp(A, action) } action { A } --- given by the assignment axiom Wp( x = 5, x = x + 1) { x= 4} x = x + 1 {x = 5 }

Mutual exclusion: (¬ in1 \/ ¬ in2) /\ in1 /\ in 2 = false Absence of unnecessary wait: ¬ in2 /\ ¬ in1

Invariant based approach CS1 CS2 do (true) do (true)  <await (¬ lock)  lock = true> <await(¬ lock)  lock = true> critical section critical section lock = false lock = false non-critical section non-critical section od od lock = in1 \/ in2 <await (¬ in2)  in1 = true>

Test and set instruction lock = false CS1 CS2 do (true) do (true)  while (TS(lock)) {}; while(TS(lock)) {}; critical section critical section lock = false lock = false non-critical section non-critical section od TS(x) = { temp = x; x = true; return temp }

Tie Breaker Algorithm in1 = false; in2 = false; last = 1 co CS1: CS2: do true  do true  last = 1; in1 = true; last = 2; in2 = true while(in2 /\ last == 1); while(in1 /\ last == 2); critical section critical section in1 = false; in2 = false; non-critical section non-critical section od od oc

Barrier synchronization Worker[i]: do true  code for task i wait for all tasks to complete od

Barrier synchronization Worker[i]: do true  code for task i <count = count + 1> < await( count == n) > od

Barrier synchronization co worker[i]: Coordinator do true  do true  code for task i; for (i = 1 to n) arrive[i] = 1 await(arrive[i]= 1); await(continue ==1) continue = 1 od od oc

Barrier synchronization co worker[i]: Coordinator do true  do true  code for task I; for (i = 1 to n) arrive[i] = 1 { await(arrive[i]= 1); await(continue[i]==1) arrive[i] = 0; } continue[i] = 0; for (i = 1 to n) continue[i] = 1 od od oc Flag rule: A process that waits for the synchronization flags should reset it.