Today’s Agenda  HW #2 Out  Replay Semaphore and Lock  Advanced Locking Advanced Topics in Software Engineering 1.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Ken Birman 1. Refresher: Dekers Algorithm Assumes two threads, numbered 0 and 1 CSEnter(int i) { int J = i^1; inside[i] = true; turn = J; while(inside[J]
– R 7 :: 1 – 0024 Spring 2010 Parallel Programming 0024 Recitation Week 7 Spring Semester 2010.
Ch 7 B.
CS Lecture 4 Programming with Posix Threads and Java Threads George Mason University Fall 2009.
1 Implementations: User-level Kernel-level User-level threads package each u.process defines its own thread policies! flexible mgt, scheduling etc…kernel.
Chapter 6: Process Synchronization
Background Concurrent access to shared data can lead to inconsistencies Maintaining data consistency among cooperating processes is critical What is wrong.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 13: October 12, 2010 Instructor: Bhuvan Urgaonkar.
Today’s Agenda  HW #3  Replay Monitor Advanced Topics in Software Engineering 1.
Today’s Agenda  Midterm: Nov 3 or 10  Finish Message Passing  Race Analysis Advanced Topics in Software Engineering 1.
02/19/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
Semaphores. Announcements No CS 415 Section this Friday Tom Roeder will hold office hours Homework 2 is due today.
CS444/CS544 Operating Systems Synchronization 2/21/2007 Prof. Searleman
Semaphores, mutexes and condition variables. semaphores Two types – Binary – 0 or 1 – Counting 0 to n Wait – decrements > 0 forces a wait Post or signal.
Semaphores CSCI 444/544 Operating Systems Fall 2008.
02/23/2004CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
02/17/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Jonathan Walpole Computer Science Portland State University
02/25/2004CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
1 Interprocess Communication Race Conditions Two processes want to access shared memory at same time.
Process Synchronization Topics: 1.Background 2.The critical-section problem 3.Semaphores 4.Critical Regions 5.Monitors Topics: 1.Background 2.The critical-section.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
02/19/2007CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
CS Introduction to Operating Systems
1 Race Conditions/Mutual Exclusion Segment of code of a process where a shared resource is accessed (changing global variables, writing files etc) is called.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
6.3 Peterson’s Solution The two processes share two variables: Int turn; Boolean flag[2] The variable turn indicates whose turn it is to enter the critical.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 14: October 14, 2010 Instructor: Bhuvan Urgaonkar.
Semaphores, Locks and Monitors By Samah Ibrahim And Dena Missak.
ICS 145B -- L. Bic1 Project: Process/Thread Synchronization Textbook: pages ICS 145B L. Bic.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
Internet Software Development Controlling Threads Paul J Krause.
1 Chapter 2.3 : Interprocess Communication Process concept  Process concept  Process scheduling  Process scheduling  Interprocess communication Interprocess.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
CS3773 Software Engineering Lecture 06 UML State Machines.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 24 Critical Regions.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-5 Process Synchronization Department of Computer Science and Software.
Today’s Agenda  Quick Review  Semaphore and Lock Advanced Topics in Software Engineering 1.
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
Lecture 6: Monitors & Semaphores. Monitor Contains data and procedures needed to allocate shared resources Accessible only within the monitor No way for.
Operating Systems Lecture Notes Synchronization Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Synchronization Emery Berger and Mark Corner University.
Advanced Topics in Software Engineering1 Today’s Agenda  HW #1  Quick Review  Finish The CS Problem  Replay Shared Variables.
CS 2200 Presentation 18b MUTEX. Questions? Our Road Map Processor Networking Parallel Systems I/O Subsystem Memory Hierarchy.
Operating Systems COMP 4850/CISG 5550 Interprocess Communication, Part II Dr. James Money.
CSC 360 Instructor: Kui Wu More on Process Synchronization Semaphore, Monitor, Condition Variables.
1 Processes and Threads Part II Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Reachability Testing of Concurrent Programs1 Reachability Testing of Concurrent Programs Richard Carver, GMU Yu Lei, UTA.
Synchronization Questions answered in this lecture: Why is synchronization necessary? What are race conditions, critical sections, and atomic operations?
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
CS 311/350/550 Semaphores. Semaphores – General Idea Allows two or more concurrent threads to coordinate through signaling/waiting Has four main operations.
Process Synchronization. Concurrency Definition: Two or more processes execute concurrently when they execute different activities on different devices.
PARALLEL PROGRAM CHALLENGES
Process Synchronization
Operating Systems CMPSC 473
Advanced Topics in Software Engineering 1
Thread Synchronization
Semaphore Originally called P() and V() wait (S) { while S <= 0
Lecture 22 Syed Mansoor Sarwar
Lecture 2 Part 2 Process Synchronization
Critical section problem
CSE 153 Design of Operating Systems Winter 19
Chapter 6: Synchronization Tools
Process/Thread Synchronization (Part 2)
Presentation transcript:

Today’s Agenda  HW #2 Out  Replay Semaphore and Lock  Advanced Locking Advanced Topics in Software Engineering 1

Advanced Topics in Software Engineering 2 Tracing/Replay for Semaphores and Locks  PV-sequence & Lock/Unlock-sequence  Trace and Replay

Advanced Topics in Software Engineering 3 Shared Objects Let P be a concurrent program that uses shared variables, semaphores and locks. The outcome of executing P with a given input depends on the order in which shared objects in P are accessed. P’s shared objects are its shared variables, semaphores, and locks.

Advanced Topics in Software Engineering 4 PV-sequence A SYN-sequence for a semaphore is referred to as a PV-sequence, which consists of a sequence of events of the following types:  completion of a P operation  completion of a V operation  start of a P operation that is never completed  start of a V operation that is never completed

Advanced Topics in Software Engineering 5 PV-sequence (cont’d) An event in a PV-sequence is encoded by the identifier (ID) of the thread that executes the P or V operation. The order in which threads complete P and V operations is not necessarily the same as the order in which these P and V operations start.

Advanced Topics in Software Engineering 6 PV-sequence (cont’d) Thread 1... s.P();... s.V();... s.V();... s.V()... Thread 2... s.V();... s.P();... s.P();... s.V()... Let s be a binary semaphore initialized with 0. 2, 1, 1, 2, 1, 2, 1, 2

Advanced Topics in Software Engineering 7 Lock/Unlock-sequence A SYN-sequence for a lock is referred to as a Lock/Unlock-sequence, which consists of a sequence of events of the following types:  completion of a lock operation  completion of a unlock operation  start of a lock operation that is never completed  start of a unlock operation that is never completed

Advanced Topics in Software Engineering 8 Lock/Unlock-sequence (cont’d) An event in a Lock/Unlock-sequence is encoded by the identified (ID) of the thread that executed the Lock or Unlock operation. The order in which threads complete Lock and Unlock operations is not necessarily the same as the order in which these Lock and Unlock operations start.

Advanced Topics in Software Engineering 9 Lock/Unlock-sequence (cont’d) Let l be a mutex lock. Thread 1... l.lock(); (1) x = 1;(2) l.unlock();(3)... Thread 2... l.lock();(1) x = 2;(2) l.unlock();(3)... 1, 1, 2, 2

Advanced Topics in Software Engineering 10 SYN-sequence for a program A SYN-sequence for a concurrent program is a collection of RW-sequence, PV-sequence, and Lock/Unlock-sequence, where there is one sequence for each shared variable, semaphore, and lock in the program.

Advanced Topics in Software Engineering 11 Replay Assume that shared variables are always safely accessed within critical sections. If we replay PV-sequence or Lock/Unlock-sequence, then the RW-sequence of each shared variable will be replayed.

Advanced Topics in Software Engineering 12 P & V methods P() { if (replay) { control.requestPermit (ID); } // enter the CS if (replay) { control.releasePermit(); } /* body of P () */ if (trace) { control.traceCompleteP (ID); } // leaving the CS } V() { if (replay) { control.requestPermit(ID); } // enter the CS if (replay) { control.releasePermit(); } /* body of P () */ if (trace) { control.traceCompleteV (ID); } // leave the CS }

Advanced Topics in Software Engineering 13 Lock & Unlock methods Lock & Unlock methods for a mutex lock will be implemented in a way that is similar to P & V methods.

Advanced Topics in Software Engineering 14 class control Each semaphore or lock is associated with a control object. In trace mode, the control object collects and records the sequence of synchronization events. In replay mode, the control object inputs the SYN- sequence of the semaphore or mutex lock and handles the calls to requestPermit and releasePermit.

Advanced Topics in Software Engineering 15 class control (cont’d) public class control { private Vector SYNsequence; // PV-sequence or Lock/Unlock-sequence; sequence of IDs private BinarySemaphore [] threads; // all semaphores initialized to 0 boolean [] hasRequested;// hasRequested[i] is true if Ti is delayed in requestPermit int index = 0; // index into SYNsequence MutexLock mutex; public control () { // initialization } public void requestPermit (int ID) { mutex.lock (); if (ID != SYNsequence[index]) { hasRequested[ID] = true; mutex.unlock (); threads[ID].P (); hasRequested[ID] = false; } else mutex.unlock (); } public void releasePermit () { mutex.lock (); ++ index; if (index < SYNSequence.size ()) { if (hasRequested[SYNsequence[index]]) { threads[SYNsequence[index]].V(); } mutex.unlock (); } public void traceCompleteP (int ID) {... } // record integer ID public void traceCompleteV (int ID) {... } // record integer ID }

Advanced Topics in Software Engineering 16 Example T1 T2 (1) (2) (3) (1) (2) (3) ID != SYNSequence[0] hasRequested[2] = true; ID == SYNSequence[0] ID == SYNSequence[1] ID == SYNSequence[2] ID == SYNSequence[3] Consider the example lock/unlock sequence discussed earlier. What happens if T2 attempts the lock operation first during replay? 1, 1, 2, 2