Ch 9: Control flow. Sequencers. Jumps. Jumps
|
|
- Naomi Richards
- 5 years ago
- Views:
Transcription
1 Ch 9: Control flow Sequencers We will study a number of alternatives traditional sequencers: sequential conditional iterative jumps, low-level sequencers to transfer control escapes, sequencers to transfer control out of commands and procedures exceptions, sequencers to signal abnormal situations A sequencer is a language construct to transfer control to some other point in a program, destination A sequencer implements a flow of control / Faculteit Wiskunde en Informatica PAGE 0 / Faculteit Wiskunde en Informatica PAGE 1 Jumps Jumps A jump transfers control to a specified program point A jump has typical the form goto L; and transfer the control to program point L, which is a label if (E 1 ) C 1 else { C 2 goto X; C 3 ; while (E 2 ) { C 4 ; X: C 5 Unrestricted jumps lead to spaghetti code, thus hard to understand, see Most programming languages support gotos Java refuses jumps, because it supports higher-level escapes and exceptions Some languages have restrictions: the jump goto L; is legal only within the scope of L in C the scope of each label is the smallest enclosing block: jumps within a block jumps from a block to an enclosing one jumps into a block from outside is not allowed / Faculteit Wiskunde en Informatica PAGE 2 / Faculteit Wiskunde en Informatica PAGE 3
2 Jumps Escapes C restricts jumps because a jump out of a block must destroy the local variables Jumps out of a procedure should lead to destroying local variables and termination of procedure activation Jumps out of a recursive procedure is even more complicated Jumps introduce unwanted complexity in the semantics of high-level programming languages An escape is a sequencer that terminates the execution of a textually enclosing command or procedure In C, C++, Java: break sequencer to break loops In C, C++, Java: return sequencer to break loops and end procedures multiple return sequencers in a procedure is hard to maintain Escapes are restricted so that control cannot be transfer out of procedures A halt sequencer stops the entire program exit() in C / Faculteit Wiskunde en Informatica PAGE 4 / Faculteit Wiskunde en Informatica PAGE 5 Exceptions Exceptions Exceptions are a mechanism to deal with abnormal situations: arithmetic operation overflows uncompleted input/output operations Exceptions take of two things: error handling Controlled termination of flow of control Code that detects an abnormal situation throws an exception the exception can be caught in another part of the program programmer have control over exceptions and handling of it C++ and Java, being object-oriented languages, treat exceptions as objects / Faculteit Wiskunde en Informatica PAGE 6 / Faculteit Wiskunde en Informatica PAGE 7
3 Exceptions Exceptions Java has a built-in Exception class every exception is a subclass of Exception every exception represents a different abnormal situation try C 0 catch (T 1 I 1 ) C 1 catch (T n I n ) C n finally C f Able to catch any exception from class T 1 or ort n if C 0 throws an exception of type T i handler C i will be executed with identifier I i bound to that exception Exceptions can be caught at various levels: static float readfloat(bufferedreader input) throws IOException, NumberFormatException { if () throw new IOException( end of input ); String literal = ; float f = Float.parseFloat(literal); return f; Float.parseFloat throws the NumberFormatException / Faculteit Wiskunde en Informatica PAGE 8 / Faculteit Wiskunde en Informatica PAGE 9 Exceptions Exceptions Method annual rainfall data may catch the NumberFormatException static float[] readannual(bufferedreader input) throws IOException { try { float r = readfloat(input); catch (NumberFormatException e) { The main program calls readannual and deals with the IOException static void main() { float[] rainfall; try { rainfall = readannual(); catch (IOException e) { / Faculteit Wiskunde en Informatica PAGE 10 / Faculteit Wiskunde en Informatica PAGE 11
4 Ch 10: Concurrency Programs and processes Why concurrency? program design becomes more complex testing becomes less effective historically, improvement of efficiency via multiprogramming systems, usage of idle resources currently, end of Moore s law, efficiency gain via multi-core processors A sequential process is a totally ordered set of steps each step is a change of state A sequential program specifies the state changes of a sequential process A concurrent program specifies the possible state changes of 2 or more sequential processes / Faculteit Wiskunde en Informatica PAGE 12 / Faculteit Wiskunde en Informatica PAGE 13 Problems with concurrency Problems with concurrency Nondeterminism: sequential programs are deterministic collateral and nondeterministic conditional commands may introduce unpredictability in sequential programs compiler is free to determine the order of execution different compilers may lead to different behavior A concurrent program is genuinely nondeterministic even for a specific compiler incorrect concurrent programs may behave correctly in general, but have sometimes unpredictable behavior Speed dependence sequential programs are speed-independent because correctness does not depend on execution speed concurrent programs are speed-dependent behavior depends on the relative speed at which its constituent sequential processes run if absolute speeds are considered, outside world, we have real-time behavior if the outcome is speed-dependent, there is a race condition / Faculteit Wiskunde en Informatica PAGE 14 / Faculteit Wiskunde en Informatica PAGE 15
5 Problems with concurrency Problems with concurrency Deadlock means that processes are unable to make progress because of mutually incompatible demands for resources mutual exclusion: a process may be given exclusive access to resources incremental acquisition: a process holds previously acquired resource while waiting for new resources no preemption: resources cannot be removed from a process until it voluntarily releases them circular waiting: a cycle of resources or processes in which each process is waiting for resources that are held by the next process in the cycle Solutions for deadlocks: Ignore them and restart system if it occurs Recovery by detecting and kill involved processes Prevention by remove some of the preconditions Avoid by scheduling of resources / Faculteit Wiskunde en Informatica PAGE 16 / Faculteit Wiskunde en Informatica PAGE 17 Problems with concurrency Process interactions Starvation A concurrent program has the liveness property if it is guaranteed that every process will make some progress over a sufficiently long period of time Free of deadlock Fair scheduling Fair scheduling means that no process needing a resource is indefinitely prevented from obtaining it Sequential and collateral commands do not allow simultaneously execution of commands The parallel command B C indicates that B and C may executed simultaneously or arbitrarily interleaved / Faculteit Wiskunde en Informatica PAGE 18 / Faculteit Wiskunde en Informatica PAGE 19
6 Process interactions Process interactions Independent processes: commands B and C are independent if the execution of B has no effect on the execution of C, and vice versa concurrent composition of independent processes is deterministic Competing processes Commands B and C are competing if they need exclusive access to the same resource r Let B be the sequence B 1 ; B 2 ; B 3 Let C be the sequence C 1 ; C 2 ; C 3 B 1, C 1, B 3, C 3 are independent, none need r B 2 and C 2 both need r, so they cannot take place simultaneously, they are critical section wrtr B C may be executed as: ; B 2 ; ; C 2 ; ; C 2 ; ; B 2 ; but not as ; B 2 C 2 ; / Faculteit Wiskunde en Informatica PAGE 20 / Faculteit Wiskunde en Informatica PAGE 21 Process interactions Concurrency primitives Communicating processes let B be the sequence B 1 ; B 2 ; B 3 let C be the sequence C 1 ; C 2 ; C 3 there is communication from B to C if B 2 produces data that C 2 consumes, so B 2 must end before C 2 starts Thus B C has the same behavior as B; C Processes B and C intercommunicate if there is communication in both directions: B C yields numerous outcomes Process until now was a flow of control through a program a conventional, heavyweight, process is a program, which involves: an address space allocation of main storage, share of CPU time access to files, devices, etc. context switching from one process to another involves a lot of time a thread is a lightweight alternative flow of control through a program without computational resources switching of threads involves swapping of content of working registers / Faculteit Wiskunde en Informatica PAGE 22 / Faculteit Wiskunde en Informatica PAGE 23
7 Concurrency primitives Concurrency primitives Process creation and control create a new child process load program code to be executed by a process start execution of a process suspend execution of a process resume execution of a (suspended) process let a process stop at the end of its execution let the creator wait for the process to stop destroy a stopped process, freeing resources create, load, start are combined into fork wait and destroy into join Process creation and control abstract operations for competition in order to make the critical sections disjoint in time acquire(r) to gain exclusive access to resource r relinquish(r) to give up exclusive access if resource r is already allocated, acquire(r) blocks the process it calls it if resource r is freed, processes waiting for access are unblocked and rescheduled abstract operations for (synchronous) communication transmit(m) called by a sender to send m receive(m) called by a receiver to wait for m asynchronous communication via broadcasting / Faculteit Wiskunde en Informatica PAGE 24 / Faculteit Wiskunde en Informatica PAGE 25 Concurrency primitives Concurrency primitives Interrupts ending a concurrent input/output operation is a infrequent operation to which the CPU should respond quickly ending input/output operations causes interrupts Spin locks and wait-free algorithms On a multiprocessor several processes may be executed simultaneously Most algorithms, Dekker s algorithm (presented by Dijkstra), Petterson s algorithm, Simpson s algorithm are complex and their behavior maybe corrupted by compiler optimizations Primitives should be built into the language events semaphores messages remote procedure calls / Faculteit Wiskunde en Informatica PAGE 26 / Faculteit Wiskunde en Informatica PAGE 27
8 Languages with concurrency primitives Object-oriented languages, e.g. Java with threads Specification languages mcrl2 CHI POOSL Scripting languages ToolBus Coordination: the way in which program and system parts interact (procedure calls, RMI,...) Representation: language and machine neutral data exchanged between components Computation: program code that carries out a specialized task A rigorous separation of coordination from computation is the key to flexible and reusable systems / Faculteit Wiskunde en Informatica PAGE 28 Architectural Layers ToolBus Architecture Coordination Representation Representation Computation Computation Single Component Single Component Cooperating Components ToolBus Tools Coordination Representation ATerms Computation common data exchange format
9 ToolBus scripts: processes Send, receive message (handshaking) Send/receive notes (broadcasting) Subscription to notes Dynamic process creation Absolute/relative delay, timeout ToolBus scripts: tools Execute/terminate tools Connect/disconnect tools Communication between process and tool is synchronous Process can send evaluation request to tool (which returns a value later on) Tool can generate events to be handled by the ToolBus Process communication: messages Messages used for synchronous, two-party communication between processes snd-msg and rec-msg synchronize sender/receiver Communication is possible if the arguments match There is two-way data transfer between sender and receiver (using result variables) Process communication: notes Notes used for asynchronous, broadcasting communication between processes Each process must subscribe to the notes it wants to receive Each process has a private note queue on which snd-note, rec-note and no-note operate
10 Process communication: subscribe to notes of a given form subscribe(compute(<str>,<int>)) unsubscribe from certain notes snd-note to all subscribers snd-note(compute(e,v)) rec-note: receive a note of a given form no-note received of given form Composite process expressions One of the atomic processes mentioned above delta (deadlock), tau (silent step) P 1 + P 2 : choice (non-deterministic) P 1. P 2 : sequential composition P 1 P 2 : parallel composition P 1 * P 2 : repetition Composite process expressions P(T 1, T 2,...): a named process (with optional parameters) will be replaced by its definition create(p(t 1, T 2,...), Pid?): dynamic process creation V := Expr: evaluate Expr and assign result to V if Expr then P 1 else P 2 fi if Expr then P 1 fi = if Expr then P 1 else delta fi Process definitions Process definition: process Pname Formals is P Formals are optional and contain a list of formal parameter names process MakeWave(N : int) is... All variables (including formals) must be declared and have a type let VarDecls in P endlet introduces variables: let E : str, V : int in... endlet
11 Tools: Tools have to be executed or connected before they can be used Requires a tool definition: tool ui is {... Introduces a new type, e.g. ui Execute a tool: execute(ui, Uid?) Receive connection request: rec-connect(ui, Uid?) Tool identification is assigned to Uid (of type uid) Tools: snd-terminate: terminate an executing tool snd-terminate(tid) rec-disconnect: receive disconnection request from tool rec-disconnect(uid) shutdown: terminate the whole ToolBus shutdown( Auction ends ) Tools snd-eval, rec-value: request tool to evaluate a term, and receive the resulting value from tool initiative: ToolBus snd-do: request tool to perform some action, there is no reply initiative: ToolBus rec-event, snd-ack-event: receive event from tool, acknowledge it after appropriate processing initiative: tool Tscripts a Tscripts consists of a list of process and tool definitions a single ToolBus configuration a ToolBus configuration describes the initial set of active processes in the ToolBus: toolbus(pname 1,..., Pname n ) Each Pname is optionally followed by parameters
Ch. 7: Generic abstraction. Generic units and instantiation. Generic units and instantiation. Generic units and instantiation
Ch. 7: Generic abstraction Generic units and instantiation Reusable program units are applicable in a variety of applications stack queue list set such program units are generic wrt the data the process
More informationPerformance Throughput Utilization of system resources
Concurrency 1. Why concurrent programming?... 2 2. Evolution... 2 3. Definitions... 3 4. Concurrent languages... 5 5. Problems with concurrency... 6 6. Process Interactions... 7 7. Low-level Concurrency
More informationMS Windows Concurrency Mechanisms Prepared By SUFIAN MUSSQAA AL-MAJMAIE
MS Windows Concurrency Mechanisms Prepared By SUFIAN MUSSQAA AL-MAJMAIE 163103058 April 2017 Basic of Concurrency In multiple processor system, it is possible not only to interleave processes/threads but
More informationChapter 5 Concurrency: Mutual Exclusion. and. Synchronization. Operating Systems: Internals. and. Design Principles
Operating Systems: Internals and Design Principles Chapter 5 Concurrency: Mutual Exclusion and Synchronization Seventh Edition By William Stallings Designing correct routines for controlling concurrent
More informationWhat is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem?
What is the Race Condition? And what is its solution? Race Condition: Where several processes access and manipulate the same data concurrently and the outcome of the execution depends on the particular
More informationCSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.
CSC 4103 - Operating Systems Spring 2008 Lecture - XII Midterm Review Tevfik Ko!ar Louisiana State University March 4 th, 2008 1 I/O Structure After I/O starts, control returns to user program only upon
More informationConcurrency, Mutual Exclusion and Synchronization C H A P T E R 5
Concurrency, Mutual Exclusion and Synchronization C H A P T E R 5 Multiple Processes OS design is concerned with the management of processes and threads: Multiprogramming Multiprocessing Distributed processing
More informationChapter 5 Concurrency: Mutual Exclusion and Synchronization
Operating Systems: Internals and Design Principles Chapter 5 Concurrency: Mutual Exclusion and Synchronization Seventh Edition By William Stallings Designing correct routines for controlling concurrent
More informationIT 540 Operating Systems ECE519 Advanced Operating Systems
IT 540 Operating Systems ECE519 Advanced Operating Systems Prof. Dr. Hasan Hüseyin BALIK (5 th Week) (Advanced) Operating Systems 5. Concurrency: Mutual Exclusion and Synchronization 5. Outline Principles
More informationConcurrency. Lecture 14: Concurrency & exceptions. Why concurrent subprograms? Processes and threads. Design Issues for Concurrency.
Lecture 14: Concurrency & exceptions Concurrency Processes and threads Semaphores, monitors and message passing Exception handling Concurrency Is is often desirable or necessary to execute parts of programs
More informationConcurrency: Deadlock and Starvation
Concurrency: Deadlock and Starvation Chapter 6 E&CE 354: Processes 1 Deadlock Deadlock = situation in which every process from a set is permanently blocked, i.e. cannot proceed with execution Common cause:
More informationCPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.
CPSC/ECE 3220 Fall 2017 Exam 1 Name: 1. Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.) Referee / Illusionist / Glue. Circle only one of R, I, or G.
More informationLast Class: Synchronization Problems. Need to hold multiple resources to perform task. CS377: Operating Systems. Real-world Examples
Last Class: Synchronization Problems Reader Writer Multiple readers, single writer In practice, use read-write locks Dining Philosophers Need to hold multiple resources to perform task Lecture 10, page
More informationDr. D. M. Akbar Hussain DE5 Department of Electronic Systems
Concurrency 1 Concurrency Execution of multiple processes. Multi-programming: Management of multiple processes within a uni- processor system, every system has this support, whether big, small or complex.
More informationModels of concurrency & synchronization algorithms
Models of concurrency & synchronization algorithms Lecture 3 of TDA383/DIT390 (Concurrent Programming) Carlo A. Furia Chalmers University of Technology University of Gothenburg SP3 2016/2017 Today s menu
More informationDealing with Issues for Interprocess Communication
Dealing with Issues for Interprocess Communication Ref Section 2.3 Tanenbaum 7.1 Overview Processes frequently need to communicate with other processes. In a shell pipe the o/p of one process is passed
More informationCHAPTER 6: PROCESS SYNCHRONIZATION
CHAPTER 6: PROCESS SYNCHRONIZATION The slides do not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams. TOPICS Background
More informationAP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS
AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this
More informationCSL373: Lecture 5 Deadlocks (no process runnable) + Scheduling (> 1 process runnable)
CSL373: Lecture 5 Deadlocks (no process runnable) + Scheduling (> 1 process runnable) Past & Present Have looked at two constraints: Mutual exclusion constraint between two events is a requirement that
More informationSynchronization I. Jo, Heeseung
Synchronization I Jo, Heeseung Today's Topics Synchronization problem Locks 2 Synchronization Threads cooperate in multithreaded programs To share resources, access shared data structures Also, to coordinate
More informationCS420: Operating Systems. Process Synchronization
Process Synchronization James Moscola Department of Engineering & Computer Science York College of Pennsylvania Based on Operating System Concepts, 9th Edition by Silberschatz, Galvin, Gagne Background
More informationProcess Management And Synchronization
Process Management And Synchronization In a single processor multiprogramming system the processor switches between the various jobs until to finish the execution of all jobs. These jobs will share the
More informationCSE 153 Design of Operating Systems
CSE 153 Design of Operating Systems Winter 2018 Midterm Review Midterm in class on Monday Covers material through scheduling and deadlock Based upon lecture material and modules of the book indicated on
More informationCS370 Operating Systems
CS370 Operating Systems Colorado State University Yashwant K Malaiya Fall 2017 Lecture 11 Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ Multilevel Feedback Queue: Q0, Q1,
More informationMutual Exclusion and Synchronization
Mutual Exclusion and Synchronization Concurrency Defined Single processor multiprogramming system Interleaving of processes Multiprocessor systems Processes run in parallel on different processors Interleaving
More informationChapter Machine instruction level 2. High-level language statement level 3. Unit level 4. Program level
Concurrency can occur at four levels: 1. Machine instruction level 2. High-level language statement level 3. Unit level 4. Program level Because there are no language issues in instruction- and program-level
More informationLast Class: Monitors. Real-world Examples
Last Class: Monitors Monitor wraps operations with a mutex Condition variables release mutex temporarily C++ does not provide a monitor construct, but monitors can be implemented by following the monitor
More informationIV. Process Synchronisation
IV. Process Synchronisation Operating Systems Stefan Klinger Database & Information Systems Group University of Konstanz Summer Term 2009 Background Multiprogramming Multiple processes are executed asynchronously.
More informationOperating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy
Operating Systems Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. AL-AZHAR University Website : eaymanelshenawy.wordpress.com Email : eaymanelshenawy@yahoo.com Reference
More informationOperating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017
Operating Systems Lecture 4 - Concurrency and Synchronization Adrien Krähenbühl Master of Computer Science PUF - Hồ Chí Minh 2016/2017 Mutual exclusion Hardware solutions Semaphores IPC: Message passing
More informationConcurrency, Thread. Dongkun Shin, SKKU
Concurrency, Thread 1 Thread Classic view a single point of execution within a program a single PC where instructions are being fetched from and executed), Multi-threaded program Has more than one point
More informationCS-537: Midterm Exam (Spring 2001)
CS-537: Midterm Exam (Spring 2001) Please Read All Questions Carefully! There are seven (7) total numbered pages Name: 1 Grading Page Points Total Possible Part I: Short Answers (12 5) 60 Part II: Long
More informationContribution:javaMultithreading Multithreading Prof. Dr. Ralf Lämmel Universität Koblenz-Landau Software Languages Team
http://101companies.org/wiki/ Contribution:javaMultithreading Multithreading Prof. Dr. Ralf Lämmel Universität Koblenz-Landau Software Languages Team Non-101samples available here: https://github.com/101companies/101repo/tree/master/technologies/java_platform/samples/javathreadssamples
More informationConcurrency. Chapter 5
Concurrency 1 Chapter 5 2 Concurrency Is a fundamental concept in operating system design Processes execute interleaved in time on a single processor Creates the illusion of simultaneous execution Benefits
More informationComputation Abstractions. Processes vs. Threads. So, What Is a Thread? CMSC 433 Programming Language Technologies and Paradigms Spring 2007
CMSC 433 Programming Language Technologies and Paradigms Spring 2007 Threads and Synchronization May 8, 2007 Computation Abstractions t1 t1 t4 t2 t1 t2 t5 t3 p1 p2 p3 p4 CPU 1 CPU 2 A computer Processes
More informationMore on Synchronization and Deadlock
Examples of OS Kernel Synchronization More on Synchronization and Deadlock Two processes making system calls to read/write on the same file, leading to possible race condition on the file system data structures
More informationConcurrency: Deadlock and Starvation. Chapter 6
Concurrency: Deadlock and Starvation Chapter 6 Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate with each other Involve conflicting needs for resources
More informationDeadlock. Concurrency: Deadlock and Starvation. Reusable Resources
Concurrency: Deadlock and Starvation Chapter 6 Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate with each other No efficient solution Involve conflicting
More informationOperating Systems Antonio Vivace revision 4 Licensed under GPLv3
Operating Systems Antonio Vivace - 2016 revision 4 Licensed under GPLv3 Process Synchronization Background A cooperating process can share directly a logical address space (code, data) or share data through
More informationChapters 5 and 6 Concurrency
Operating Systems: Internals and Design Principles, 6/E William Stallings Chapters 5 and 6 Concurrency Patricia Roy Manatee Community College, Venice, FL 2008, Prentice Hall Concurrency When several processes/threads
More informationCSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs
CSE 451: Operating Systems Winter 2005 Lecture 7 Synchronization Steve Gribble Synchronization Threads cooperate in multithreaded programs to share resources, access shared data structures e.g., threads
More informationConcurrent Programming using Threads
Concurrent Programming using Threads Threads are a control mechanism that enable you to write concurrent programs. You can think of a thread in an object-oriented language as a special kind of system object
More informationProcess Synchronisation (contd.) Deadlock. Operating Systems. Spring CS5212
Operating Systems Spring 2009-2010 Outline Process Synchronisation (contd.) 1 Process Synchronisation (contd.) 2 Announcements Presentations: will be held on last teaching week during lectures make a 20-minute
More informationHigh Performance Computing Course Notes Shared Memory Parallel Programming
High Performance Computing Course Notes 2009-2010 2010 Shared Memory Parallel Programming Techniques Multiprocessing User space multithreading Operating system-supported (or kernel) multithreading Distributed
More informationConcurrent Programming
Concurrency Concurrent Programming A sequential program has a single thread of control. Its execution is called a process. A concurrent program has multiple threads of control. They may be executed as
More informationChapter 6: Synchronization. Operating System Concepts 8 th Edition,
Chapter 6: Synchronization, Silberschatz, Galvin and Gagne 2009 Outline Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization
More informationCS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University
CS 333 Introduction to Operating Systems Class 3 Threads & Concurrency Jonathan Walpole Computer Science Portland State University 1 The Process Concept 2 The Process Concept Process a program in execution
More informationLast Class: Deadlocks. Today
Last Class: Deadlocks Necessary conditions for deadlock: Mutual exclusion Hold and wait No preemption Circular wait Ways of handling deadlock Deadlock detection and recovery Deadlock prevention Deadlock
More informationSynchronization I. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University
Synchronization I Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Today s Topics Synchronization problem Locks 2 Synchronization Threads cooperate
More information10/17/ Gribble, Lazowska, Levy, Zahorjan 2. 10/17/ Gribble, Lazowska, Levy, Zahorjan 4
Temporal relations CSE 451: Operating Systems Autumn 2010 Module 7 Synchronization Instructions executed by a single thread are totally ordered A < B < C < Absent synchronization, instructions executed
More informationSSC - Concurrency and Multi-threading Advanced topics about liveness
SSC - Concurrency and Multi-threading Advanced topics about liveness Shan He School for Computational Science University of Birmingham Module 06-19321: SSC Outline Outline of Topics Review what we learned
More informationSynchronization Principles
Synchronization Principles Gordon College Stephen Brinton The Problem with Concurrency Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms
More informationG Programming Languages Spring 2010 Lecture 13. Robert Grimm, New York University
G22.2110-001 Programming Languages Spring 2010 Lecture 13 Robert Grimm, New York University 1 Review Last week Exceptions 2 Outline Concurrency Discussion of Final Sources for today s lecture: PLP, 12
More informationQuestion 1. Notes on the Exam. Today. Comp 104: Operating Systems Concepts 11/05/2015. Revision Lectures
Comp 104: Operating Systems Concepts Revision Lectures Today Here are a sample of questions that could appear in the exam Please LET ME KNOW if there are particular subjects you want to know about??? 1
More informationLecture 9: Midterm Review
Project 1 Due at Midnight Lecture 9: Midterm Review CSE 120: Principles of Operating Systems Alex C. Snoeren Midterm Everything we ve covered is fair game Readings, lectures, homework, and Nachos Yes,
More informationChapter 6 Concurrency: Deadlock and Starvation
Operating Systems: Internals and Design Principles Chapter 6 Concurrency: Deadlock and Starvation Seventh Edition By William Stallings Operating Systems: Internals and Design Principles When two trains
More informationConcurrency in Java Prof. Stephen A. Edwards
Concurrency in Java Prof. Stephen A. Edwards The Java Language Developed by James Gosling et al. at Sun Microsystems in the early 1990s Originally called Oak, first intended application was as an OS for
More informationEECE.4810/EECE.5730: Operating Systems Spring 2017 Homework 2 Solution
1. (15 points) A system with two dual-core processors has four processors available for scheduling. A CPU-intensive application (e.g., a program that spends most of its time on computation, not I/O or
More informationRecap: Thread. What is it? What does it need (thread private)? What for? How to implement? Independent flow of control. Stack
What is it? Recap: Thread Independent flow of control What does it need (thread private)? Stack What for? Lightweight programming construct for concurrent activities How to implement? Kernel thread vs.
More informationProcess Synchronisation (contd.) Operating Systems. Autumn CS4023
Operating Systems Autumn 2017-2018 Outline Process Synchronisation (contd.) 1 Process Synchronisation (contd.) Synchronization Hardware 6.4 (SGG) Many systems provide hardware support for critical section
More informationConcurrency. Glossary
Glossary atomic Executing as a single unit or block of computation. An atomic section of code is said to have transactional semantics. No intermediate state for the code unit is visible outside of the
More informationChapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6.
Part Three - Process Coordination Chapter 6: Synchronization 6.1 Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure
More informationCS477 Formal Software Development Methods / 39
CS477 Formal Software Development Methods 2112 SC, UIUC egunter@illinois.edu http://courses.engr.illinois.edu/cs477 SPIN Beginners Tutorial April 11, 2018 Hello World /* A "Hello World" Promela model for
More informationChapter 13 Topics. Introduction. Introduction
Chapter 13 Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Java Threads C# Threads Statement-Level Concurrency Copyright 2006 Pearson Addison-Wesley. All rights reserved.
More informationChapter 6: Process Synchronization
Chapter 6: Process Synchronization Objectives Introduce Concept of Critical-Section Problem Hardware and Software Solutions of Critical-Section Problem Concept of Atomic Transaction Operating Systems CS
More informationChapter 6: Process Synchronization
Chapter 6: Process Synchronization Chapter 6: Synchronization 6.1 Background 6.2 The Critical-Section Problem 6.3 Peterson s Solution 6.4 Synchronization Hardware 6.5 Mutex Locks 6.6 Semaphores 6.7 Classic
More informationMultiple Inheritance. Computer object can be viewed as
Multiple Inheritance We have seen that a class may be derived from a given parent class. It is sometimes useful to allow a class to be derived from more than one parent, inheriting members of all parents.
More informationIntroduction to Model Checking
Introduction to Model Checking René Thiemann Institute of Computer Science University of Innsbruck WS 2007/2008 RT (ICS @ UIBK) week 4 1/23 Outline Promela - Syntax and Intuitive Meaning Promela - Formal
More informationGeneral Objectives: To understand the process management in operating system. Specific Objectives: At the end of the unit you should be able to:
F2007/Unit5/1 UNIT 5 OBJECTIVES General Objectives: To understand the process management in operating system Specific Objectives: At the end of the unit you should be able to: define program, process and
More informationSystems Programming & Scripting
Systems Programming & Scripting Lecture 10: C# Threading Introduction, Accessing Shared Resources Based on: An Introduction to programming with C# Threads By Andrew Birrell, Microsoft, 2005 Examples from
More informationThreads and Parallelism in Java
Threads and Parallelism in Java Java is one of the few main stream programming languages to explicitly provide for user-programmed parallelism in the form of threads. A Java programmer may organize a program
More informationCSE 451: Operating Systems Winter Lecture 7 Synchronization. Hank Levy 412 Sieg Hall
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization Hank Levy Levy@cs.washington.edu 412 Sieg Hall Synchronization Threads cooperate in multithreaded programs to share resources, access shared
More informationResource management. Real-Time Systems. Resource management. Resource management
Real-Time Systems Specification Implementation Verification Mutual exclusion is a general problem that exists at several levels in a real-time system. Shared resources internal to the the run-time system:
More informationProcesses and Non-Preemptive Scheduling. Otto J. Anshus
Processes and Non-Preemptive Scheduling Otto J. Anshus Threads Processes Processes Kernel An aside on concurrency Timing and sequence of events are key concurrency issues We will study classical OS concurrency
More informationNotes on the Exam. Question 1. Today. Comp 104:Operating Systems Concepts 11/05/2015. Revision Lectures (separate questions and answers)
Comp 104:Operating Systems Concepts Revision Lectures (separate questions and answers) Today Here are a sample of questions that could appear in the exam Please LET ME KNOW if there are particular subjects
More informationMidterm Exam Amy Murphy 19 March 2003
University of Rochester Midterm Exam Amy Murphy 19 March 2003 Computer Systems (CSC2/456) Read before beginning: Please write clearly. Illegible answers cannot be graded. Be sure to identify all of your
More informationThreads. Concurrency. What it is. Lecture Notes Week 2. Figure 1: Multi-Threading. Figure 2: Multi-Threading
Threads Figure 1: Multi-Threading Figure 2: Multi-Threading Concurrency What it is 1. Two or more threads of control access a shared resource. Scheduler operation must be taken into account fetch-decode-execute-check
More informationChapter 13. Concurrency ISBN
Chapter 13 Concurrency ISBN 0-321-49362-1 Chapter 13 Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Ada Support for Concurrency Java Threads C# Threads
More informationLecture. DM510 - Operating Systems, Weekly Notes, Week 11/12, 2018
Lecture In the lecture on March 13 we will mainly discuss Chapter 6 (Process Scheduling). Examples will be be shown for the simulation of the Dining Philosopher problem, a solution with monitors will also
More informationDr. Rafiq Zakaria Campus. Maulana Azad College of Arts, Science & Commerce, Aurangabad. Department of Computer Science. Academic Year
Dr. Rafiq Zakaria Campus Maulana Azad College of Arts, Science & Commerce, Aurangabad Department of Computer Science Academic Year 2015-16 MCQs on Operating System Sem.-II 1.What is operating system? a)
More informationPreemptive Scheduling and Mutual Exclusion with Hardware Support
Preemptive Scheduling and Mutual Exclusion with Hardware Support Thomas Plagemann With slides from Otto J. Anshus & Tore Larsen (University of Tromsø) and Kai Li (Princeton University) Preemptive Scheduling
More informationRemaining Contemplation Questions
Process Synchronisation Remaining Contemplation Questions 1. The first known correct software solution to the critical-section problem for two processes was developed by Dekker. The two processes, P0 and
More informationLesson 6: Process Synchronization
Lesson 6: Process Synchronization Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks Semaphores Classic Problems of Synchronization
More informationRoadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - III Processes. Louisiana State University. Processes. September 1 st, 2009
CSC 4103 - Operating Systems Fall 2009 Lecture - III Processes Tevfik Ko!ar Louisiana State University September 1 st, 2009 1 Roadmap Processes Basic Concepts Process Creation Process Termination Context
More informationCOMP 150-CCP Concurrent Programming. Lecture 12: Deadlock. Dr. Richard S. Hall
COMP 150-CCP Concurrent Programming Lecture 12: Deadlock Dr. Richard S. Hall rickhall@cs.tufts.edu Concurrent programming February 28, 2008 Scenario Process 1 gets the lock for object A and wants to lock
More informationConcurrency: a crash course
Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Concurrency: a crash course Concurrent computing Applications designed as a collection of computational units that may execute
More informationProcesses and Threads. Industrial Programming. Processes and Threads (cont'd) Processes and Threads (cont'd)
Processes and Threads Industrial Programming Lecture 5: C# Threading Introduction, Accessing Shared Resources Based on: An Introduction to programming with C# Threads By Andrew Birrell, Microsoft, 2005
More informationChapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures
Chapter 5: Procedural abstraction Proper procedures and function procedures Abstraction in programming enables distinction: What a program unit does How a program unit works This enables separation of
More informationProcess Synchronization
CSC 4103 - Operating Systems Spring 2007 Lecture - VI Process Synchronization Tevfik Koşar Louisiana State University February 6 th, 2007 1 Roadmap Process Synchronization The Critical-Section Problem
More informationCS533 Concepts of Operating Systems. Jonathan Walpole
CS533 Concepts of Operating Systems Jonathan Walpole Introduction to Threads and Concurrency Why is Concurrency Important? Why study threads and concurrent programming in an OS class? What is a thread?
More informationCS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University
CS 333 Introduction to Operating Systems Class 3 Threads & Concurrency Jonathan Walpole Computer Science Portland State University 1 Process creation in UNIX All processes have a unique process id getpid(),
More informationComp 204: Computer Systems and Their Implementation. Lecture 25a: Revision Lectures (separate questions and answers)
Comp 204: Computer Systems and Their Implementation Lecture 25a: Revision Lectures (separate questions and answers) 1 Today Here are a sample of questions that could appear in the exam Please LET ME KNOW
More informationModule 1. Introduction:
Module 1 Introduction: Operating system is the most fundamental of all the system programs. It is a layer of software on top of the hardware which constitutes the system and manages all parts of the system.
More informationOperating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst
Operating Systems CMPSCI 377 Spring 2017 Mark Corner University of Massachusetts Amherst Clicker Question #1 public static void main(string[] args) { (new Thread(new t1())).start(); (new Thread(new t2())).start();}
More informationThe Deadlock Problem. A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.
Deadlock The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set Example semaphores A and B, initialized to 1 P 0 P
More informationChapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition
Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks
More informationDeadlock and Starvation
Deadlock and Starvation Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate with each other Involve conflicting needs for resources by two or more
More informationConcurrency Control. Synchronization. Brief Preview of Scheduling. Motivating Example. Motivating Example (Cont d) Interleaved Schedules
Brief Preview of Scheduling Concurrency Control Nan Niu (nn@cs.toronto.edu) CSC309 -- Summer 2008 Multiple threads ready to run Some mechanism for switching between them Context switches Some policy for
More informationThreads Questions Important Questions
Threads Questions Important Questions https://dzone.com/articles/threads-top-80-interview https://www.journaldev.com/1162/java-multithreading-concurrency-interviewquestions-answers https://www.javatpoint.com/java-multithreading-interview-questions
More informationJava Threads. COMP 585 Noteset #2 1
Java Threads The topic of threads overlaps the boundary between software development and operation systems. Words like process, task, and thread may mean different things depending on the author and the
More information