Today’s Agenda  HW #3  Replay Monitor Advanced Topics in Software Engineering 1.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Operating Systems: Monitors 1 Monitors (C.A.R. Hoare) higher level construct than semaphores a package of grouped procedures, variables and data i.e. object.
Operating Systems Lecture 7.
Detecting Bugs Using Assertions Ben Scribner. Defining the Problem  Bugs exist  Unexpected errors happen Hardware failures Loss of data Data may exist.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Section 3. True/False Changing the order of semaphores’ operations in a program does not matter. False.
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
Chapter 6: Process Synchronization
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Concurrent Programming James Adkison 02/28/2008. What is concurrency? “happens-before relation – A happens before B if A and B belong to the same process.
Testing Concurrent/Distributed Systems Review of Final CEN 5076 Class 14 – 12/05.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 13: October 12, 2010 Instructor: Bhuvan Urgaonkar.
Monitors Chapter 7. The semaphore is a low-level primitive because it is unstructured. If we were to build a large system using semaphores alone, the.
Today’s Agenda  Midterm: Nov 3 or 10  Finish Message Passing  Race Analysis Advanced Topics in Software Engineering 1.
MPI Program Structure Self Test with solution. Self Test 1.How would you modify "Hello World" so that only even-numbered processors print the greeting.
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
Chapter 2.3 : Interprocess Communication
1 Concurrency: Deadlock and Starvation Chapter 6.
Java Review 2 – Errors, Exceptions, Debugging Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Software Testing Sudipto Ghosh CS 406 Fall 99 November 9, 1999.
1 Concurrency: Deadlock and Starvation Chapter 6.
Dr. Pedro Mejia Alvarez Software Testing Slide 1 Software Testing: Building Test Cases.
Monitor  Giving credit where it is due:  The lecture notes are borrowed from Dr. I-Ling Yen at University of Texas at Dallas  I have modified them and.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
Concurrency, Mutual Exclusion and Synchronization.
Operating Systems Distributed Coordination. Topics –Event Ordering –Mutual Exclusion –Atomicity –Concurrency Control Topics –Event Ordering –Mutual Exclusion.
Semaphores, Locks and Monitors By Samah Ibrahim And Dena Missak.
TRANSACTION MANAGEMENT R.SARAVANAKUAMR. S.NAVEEN..
Today’s Agenda  HW #1  Finish Introduction  Input Space Partitioning Software Testing and Maintenance 1.
Multi-Threaded Programming Design CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
Today’s Agenda  Reminder: HW #1 Due next class  Quick Review  Input Space Partitioning Software Testing and Maintenance 1.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Agenda Fail Stop Processors –Problem Definition –Implementation with reliable stable storage –Implementation without reliable stable storage Failure Detection.
ICS 313: Programming Language Theory Chapter 13: Concurrency.
Multithreading in JAVA
Today’s Agenda  Quick Review  Monitor Advanced Topics in Software Engineering 1.
Sheet 3 HANDLING EXCEPTIONS Advanced Programming using Java By Nora Alaqeel.
Advanced Topics in Software Engineering 1 Message Passing  Introduction  Comm. Channels  Logical Timestamps  Message-Based Solutions.
Today’s Agenda  HW #2 Out  Replay Semaphore and Lock  Advanced Locking Advanced Topics in Software Engineering 1.
Today’s Agenda  Quick Review  Semaphore and Lock Advanced Topics in Software Engineering 1.
Consider the Java code snippet below. Is it a legal use of Java synchronization? What happens if two threads A and B call get() on an object supporting.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 3 Friday 03 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Advanced Topics in Software Engineering1 Today’s Agenda  HW #1  Quick Review  Finish The CS Problem  Replay Shared Variables.
Program Correctness. The designer of a distributed system has the responsibility of certifying the correctness of the system before users start using.
Chapter 71 Monitors (7.7)  A high-level-language object-oriented concept that attempts to simplify the programming of synchronization problems  A synchronization.
CS4315A. Berrached:CMS:UHD1 Process Synchronization Chapter 8.
Process Synchronization. Objectives To introduce the critical-section problem, whose solutions can be used to ensure the consistency of shared data To.
Agenda  Quick Review  Finish Introduction  Java Threads.
Reachability Testing of Concurrent Programs1 Reachability Testing of Concurrent Programs Richard Carver, GMU Yu Lei, UTA.
Producer/Consumer CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
Jonathan Walpole Computer Science Portland State University
CS510 Operating System Foundations
Advanced Topics in Software Engineering 1
CS510 Operating System Foundations
Monitors Chapter 7.
CSE 451: Operating Systems Winter 2004 Module 7+ Monitor Supplement
Monitors Chapter 7.
CSE 451: Operating Systems Autumn Lecture 8 Semaphores and Monitors
Monitors Chapter 7.
Monitor Giving credit where it is due:
Regression Testing.
Chapter 6: Synchronization Tools
Java Chapter 3 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Today’s Agenda  HW #3  Replay Monitor Advanced Topics in Software Engineering 1

Advanced Topics in Software Engineering 2 Tracing/Replay/Testing for Monitors  Simple M-sequences  M-sequences  Correctness and Faults

Advanced Topics in Software Engineering 3 Entry-based Execution We assume that (1) all shared variables are accessed inside a monitor; and (2) the only source of non- determinism in a program is due to uncertainty with thread scheduling. The executions of such a program is referred to as entry-based executions, as their behaviors are determined by the order in which the threads enter/reentry the monitor.

Advanced Topics in Software Engineering 4 Entry-based Execution (cont’d) An entry-based execution can be replayed if the order in which threads (re)enter the monitor is repeated.

Advanced Topics in Software Engineering 5 Simple M-sequence A simple M-sequence can be used to replay a program’s execution during debugging. The synchronization events in a simple M-sequence depend on the type of monitors being used.

Advanced Topics in Software Engineering 6 Simple M-sequence (cont’d) A simple M-sequence for an SC monitor consists of the following two types of synchronization events: (1) entry into the monitor by a new thread; and (2) reentry into the monitor by a signaled thread. A simple M-sequence for an SU monitor consists of the only type of synchronization event: entry into the monitor by a new thread. An event in a simple M-sequence is denoted by the identifier (ID) of the thread that executed the event.

Advanced Topics in Software Engineering 7 Example Consider the bounded buffer monitor. Assume there is a single Producer thread (with ID 1) and a single Consumer thread (with ID 2). With SC monitor, a possible simple M-sequence is (2,1,2,1,1,2,2). The equivalent M-sequence with SU monitor is (2,1,1,1,2,2).

Advanced Topics in Software Engineering 8 Tracing/Replay (SU) In MonitorSU, mutex controls entry into the monitor. During execution, enterMonitor is modified to send entry event to a control monitor, which records the event into a trace file. To replay a simple M-sequence, a thread requests an entry permit from the control monitor to enter the monitor, and releases the permit to allow the next one to enter.

Advanced Topics in Software Engineering 9 enterMonitor public void enterMonitor () { if (replayMode) control.requestEntryPermit (ID); mutex.P (); if (replayMode) control.releasentryPermit (); else control.traceMonitorEntry (ID); }

Advanced Topics in Software Engineering 10 Control class Control extends MonitorSC () { Control () { } public void requestEntryPermit (int ID) { enterMonitor (); if (ID != ((Integer) simpleMSequence.elementAt(index)).intValue()) { threads[ID].waitC (); } exitMonitor (); } public void releaseEntryPermit () { enterMonitor (); if (index < simpleMSequence.size() – 1) { ++ index; threads[((Integer) simpleMSequence.elementAt(index)).intValue()].signalC(); } exitMonitor (); } public void traceMonitorEntry (int ID) { // record ID in trace file } public void traceMonitorReEntry (int ID) { … } private vector simpleMSequences; private ConditionVariable[] threads; private int index = 1; }

Advanced Topics in Software Engineering 11 Tracing/Replay (SC) Tracing/Replay for SC monitor needs to record the reentry event, in addition to the entry event. Besides enterMonitor, waitC method also needs to be modified.

Advanced Topics in Software Engineering 12 waitC public void waitC () { numWaitingThreads ++; threadQue.VP (mutex); if (replayMode) control.requestEntryPermit (ID); mutex.P (); if (replayMode) control.releaseEntryPermit (); else control.traceMonitorReEntry (ID); }

Advanced Topics in Software Engineering 13 Tracing/Replay/Testing for Monitors  Simple M-sequences  M-sequences  Correctness and Faults

Advanced Topics in Software Engineering 14 Regression Testing When a failure is detected during an execution, we want to replay the execution, perhaps for many times, to locate the fault that has caused the failure. After the fault is located, the program is then modified to correct the fault. Regression testing must be performed to ensure that the fault has been corrected and no new faults were introduced.

Advanced Topics in Software Engineering 15 Regression Testing (cont’d) Regression testing requires that we determine whether or not a particular SYN-sequence is feasible. (This is different from the replay problem. Why?) A SYN-sequence may represent an illegal behavior that was observed when the program failed. In this case, the sequence is expected to be infeasible. If the SYN-sequence represents a legal behavior, then the sequence is expected to remain feasible during RT.

Advanced Topics in Software Engineering 16 A simple M-sequence is insufficient… Consider a program that contains an SU monitor for a two-slot buffer. Assume that there is a single producer (Thread 1) and a single consumer (Thread 2). A possible simple M-sequence is (1,1,1,2,2,2). During replay, a thread always execute the same method as it did in the original execution. However, during RT, this is no longer true (why?).

Advanced Topics in Software Engineering 17 Still insufficient … Now we get a new M-sequence: ((1, deposit), (1, deposit), (1, deposit), (2, withdraw), (2, withdraw)) If the third item was actually deposited, then the first item was lost. However, if the third deposit operation was actually blocked in full.wait, then the program still behaves correctly.

Advanced Topics in Software Engineering 18 M-sequence A complete M-sequence consists of the following types of events:  the entry of a monitor method and, for SC monitors, the reentry of a monitor  the exit of a monitor method  the start of execution of a wait operation  the start of execution of a signal, or signalAndExit, or signalAll operation.

Advanced Topics in Software Engineering 19 M-sequence (cont’d) Each event in a M-sequence is encoded in the following format: (Vi, Ti, Mi, Ci), where  Vi: the type of this event  Ti: the ID of the thread executing this event  Mi: the monitor method of this event  Ci: the name of the condition variable if applicable

Advanced Topics in Software Engineering 20 Example ( (enter, consumer, withdraw, NA), (wait, consumer, withdraw, notEmpty), (enter,producer, deposit, NA), (signal,producer, deposit, notEmtpy), (exit,producer, deposit, NA), (reenter, consumer, withdraw, NA), (signal,consumer, withdraw, notFull), (exit,consumer, withdraw, NA) )

Advanced Topics in Software Engineering 21 Feasibility Determination Before a thread can perform a monitor operation, it requests permission from a control monitor. The control monitor is responsible for reading a recorded M-sequence and forcing the execution to proceed according to the sequence. If the M-sequence is found to be infeasible, the control module displays a message and terminates the program.

Advanced Topics in Software Engineering 22 enterMonitor public void enterMonitor (String methodName) { if (testMode) { control.requestMPermit (ENTRY, threadID, methodName, “NA”); } mutex.P (); if (testMode) { control.releaseMPermit (); } else { control.trace (ENTRY, threadID, methodName, “NA”); }

Advanced Topics in Software Engineering 23 waitC public void waitC () { if (testMode) { control.requestMPermit (WAIT, threadID, methodName, conditionName); } else { control.trace (WAIT, threadID, methodName, conditionName); } numWaitingThreads ++; threadQue.VP (mutex); if (testMode) { control.requestMPermit (REENTRY, threadID, methodName, “NA”); } mutex.P (); if (testMode) { control.releaseMPermit (); } else { control.trace (REENTRY, threadID, methodName, “NA”); }

Advanced Topics in Software Engineering 24 signalC & exitMonitor public void signalC () { if (testMode) { control.requestMPermit (SIGNAL, threadID, methodName, conditionName); } else { control.trace (SIGNAL, threadID, methodName, conditionName); } if (numWaitingThreads > 0) { numWaitingThreads --; threadQue.V (); } public void exitMonitor () { if (testMode) { control.requestMPermit (EXIT, threadID, methodName, “NA”); } else { control.trace (EXIT, threadID, methodName, “NA”); } mutex.V(); }

Advanced Topics in Software Engineering 25 Control public void requestEntryPermit (EventType et, int ID, String methodName, String conditionName) { monitorEvent nextEvent = (MonitorEvent) Msequence.elementAt(index); if (ID != nextEvent.getThreadID ()) { threads[ID].waitC (); nextEvent = (MonitorEvent) Msequence.elementAt (index); } if (!(et.equals(nextEvent.getEventType()))) { // issue diagnostic and terminate } if (!(methodName.equals(nextEvent.getMethodName()))) { // issue diagnostic and terminate} if (et.equals(WAIT) || et.equals(SIGNAL)) { if (!(conditionName.equals(nextEvent.getConditionName()))) { // issue diagnostic and terminate} ++ index; if (index < Msequence.size ()) threads [((MonitorEvent) Msequence.elementAt(index)).getThreadID()].signalC(); } else if (et.equals(EXIT)) { ++ index; if (index < Msequence.size ()) { threads[((MonitorEvent) Msequence.elementAt(index)).getThreadID()].signalC(); } public void releaseEntryPermit () { if (index < simpleMSequence.size() – 1) { ++ index; threads[((MonitorEvent) MSequence.elementAt(index)).getThreadID()].signalC(); }

Advanced Topics in Software Engineering 26 releaseMPermit This method is called when the current event is of type ENTRY or REENTRY. It will signal the thread waiting for the next event. What happens to events of type WAIT, SIGNAL, or EXIT?

Advanced Topics in Software Engineering 27 It is undecidable... An M-sequence is feasible if and only if the M- sequence is completely exercised. However, the problem of determining whether a concurrent program terminates for a given input and SYN-sequence is in general undecidable! That is, there does not exist an algorithm f such that f: P  I  Q  { feasible, infeasible }.

Advanced Topics in Software Engineering 28 Timeout In practice, we can specify a maximum time interval that is allowed between two consecutive events. This “timeout” value represents the maximum amount of time that the controller is willing to wait for the next event to occur.

Advanced Topics in Software Engineering 29 watchDog fi n al class watchDog extends Thread { public void run () { while (index < Msequence.size ()) { int saveIndex = index; try { Thread.sleep (2000); } catch (InterruptedException e) {} if (saveIndex == index) { // issue diagnostic and exit program }

Advanced Topics in Software Engineering 30 Tracing/Replay/Testing for Monitors  Simple M-sequences  M-sequences  Correctness and Faults

Advanced Topics in Software Engineering 31 Feasible Sequences Let P be a concurrent program. A SYN-sequence is said to be feasible for P with input X if this SYN- sequence can possibly be exercised by one execution of P with input X. Feasible(P, X) = the set of feasible SYN-sequences of P with input X.

Advanced Topics in Software Engineering 32 Valid Sequences A SYN-sequence is said to be valid for P with input X if this SYN-sequence is allowed to be exercised during an execution of P with input X by the specification of P. Valid(P, X) = the set of valid SYN-sequences of P with input X.

Advanced Topics in Software Engineering 33 Correctness P is said to be correct for input X (with respect to the specification of P) if  Feasible(P, X) = Valid(P, X) and  every possible execution of P with input X produces the correct (or expected) results.

Advanced Topics in Software Engineering 34 Synchronization Fault A program P has a synchronization fault if Feasible(P, X)  Valid(P, X), which consists of two possible conditions:  There exists at least one SYN-sequence that is feasible but invalid for P with input X.  There exists at least one SYN-sequence that is valid but infeasible for P with input X.

Advanced Topics in Software Engineering 35 Computational Fault A program P has a computational fault if there exists an execution of P with input X that exercises a valid (and feasible) SYN-sequence, but computes an incorrect results.

Advanced Topics in Software Engineering 36 Synchronization or Computation Fault? Let S be a SYN-sequence exercised by an execution of P with input X. Let R be the results of the execution.  S is valid and R is correct.  S is valid and R is incorrect.  S is invalid and R is incorrect.  S is invalid and R is correct.

Advanced Topics in Software Engineering 37 Example monitor class BoundedBuffer { private int fullSlots = 0, capacity = 0; private char[] buffer = null; private int in = 0, out = 0; private ConditionVariable notFull = new ConditionVariable (); private ConditionVariable notEmpty = new ConditionVariable (); public BoundedBuffer (int capacity) { this.capacity = capacity; buffer = new int [capacity]; } public void deposit (char value) { if (fullSlots > capacity) notFull.wait (); buffer[in] = value; in = (in + 1) % capacity; ++ fullSlots; notEmpty.signal (); } public char withdraw () { char value; if (fullSlots == 0) notEmpty.wait (); value = buffer[out]; out = (out + 1) % capacity; -- fullSlots; notFull.signal (); return value; }

Advanced Topics in Software Engineering 38 Example (cont’d) ((enter, producer,deposit,NA), (signal,producer,deposit,notEmpty), (exit,producer, deposit,NA), (enter,producer, deposit,NA), (signal,producer,deposit,notEmpty), (exit,producer, deposit,NA), (enter,producer, deposit,NA), (signal,producer,deposit,notEmpty), (exit,producer, deposit,NA), (enter,consumer, withdraw,NA), (signal,consumer,withdraw,notFull), (exit,consumer, withdraw,NA), (enter,consumer, withdraw,NA), (signal,consumer,withdraw,notFull), (exit,consumer, withdraw,NA), (enter,consumer, withdraw,NA), (signal,consumer,withdraw,notFull), (exit,consumer, withdraw,NA) )

Advanced Topics in Software Engineering 39 Example (cont’d) Consider an execution in which the producer deposits items ‘A’, ‘B’, ‘C’. What is the output?

Advanced Topics in Software Engineering 40 Example (cont’d) Consider an execution in which the producer deposits items ‘C’, ‘B’, ‘C’. What is the output?