Concurrency. Lecture 14: Concurrency & exceptions. Why concurrent subprograms? Processes and threads. Design Issues for Concurrency.

Size: px
Start display at page:

Download "Concurrency. Lecture 14: Concurrency & exceptions. Why concurrent subprograms? Processes and threads. Design Issues for Concurrency."

Transcription

1 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 concurrently (in parallel). We can have physical concurrency two or more processors are used logical concurrency Conceptual concurrency which physically may be sequential (interleaving) Levels of concurrency Instruction level concurrent execution of machine instructions Statement level concurrent execution of statements. SIMD/MIMD Subprogram level concurrent execution of subprograms Program level concurrent execution of programs 1 2 Why concurrent subprograms? Processes and threads Many domains lend themselves naturally to concurrency. Nature / real life is parallel (aircraft control etc. ) Efficient use of multiprocessor architectures Needed in many interactive systems User / user and system / user Suitable language concepts is needed. The execution of a parallel program consists of several threads of control. A process (task) is a unit that can provide one thread of control, and be executed concurrently with other units. Synchronization is needed to work with common data Synchronization guarantees that S in thread T is executed correctly before or after S in thread T competition synchronization occurs if a resource (e.g a printer) can t be shared (mutual exclusion); order isn t important cooperation synchronization occurs when tasks have common goals; order is important (ex: producer-consumer) 3 4 Processes Design Issues for Concurrency A scheduler distributes processes on processors Heavyweight or lightweight processes Possible states: New Ready Running Blocked Dead Possible problems Deadlock Starvation (=> Fair scheduling) Non-determinism Speed dependent (real time) Providing competition and cooperation synchronization Semaphores Monitors Message passing Controlling task scheduling How and when tasks start and end execution How and when are tasks created 5 6 1

2 Semaphores A semaphore (Dijkstra 1965) is a data structure with two uninterruptible operations wait and release. Often they surround the code that is subject to synchronization. A semaphore has a counter (capacity) 0 and a queue (initially empty) for blocked processes If a process P executes wait(s) and the capacity of s is > 0 it is decreased by 1 otherwise P is placed in the semaphore s queue If a process P executes release(s) and the queue of s is empty its capacity is increased by 1 Otherwise the first process in the task-ready queue is activated (and is removed from the queue) Semaphores The semaphore operations must be indivisible! Initial value =1 => mutual exclusion (binary semaphore) If more than one semaphore ; order is crucial! Wrong order may lead to deadlock The programmer is responsible for the correct use of the semaphore. (Compiler cannor check) Easy to make errors! Errors in comp.synch => e.g. deadlock Errors in coop.synch => e.g buffer overflow Examples: Sebesta or Systemnära prog. 7 8 Monitors Message Passing A monitor encapsulates data structures and the operations which give access to them. (ADT!) Only one process at a time is given access to the monitor. A datatype queue is defined to facilitate cooperating synchronization. Its operations delay and continue can only be executed in a monitor. When delay(q) is executed the process is blocked, put in queue q. Other processes are can access the monitor. When continue(q) is executed the process releases the monitor, and the first process in q is activated. Monitor op:s, e.g. insert / remove uses delay/continue Message passing is a general model for concurrency It can model both semaphores and monitors It is not just for competition synchronization Central idea: task communication is like seeing a doctor--most of the time she waits for you or you wait for her, but when you are both ready, you get together, or rendezvous Synchronous (above) or asynchronous 9 10 Message Passing Rendezvous Ada synchronization by message passing To support concurrent tasks with message passing, a language needs: - A mechanism to allow a task to indicate when it is willing to accept messages - A way to remember who is waiting to have its message accepted and some fair way of choosing the next message When a sender task s message is accepted by a receiver task, the actual message transmission is called a rendezvous In Ada processes can send and receive synchronization messages. If both sender and receiver are ready a rendezvous occurs, otherwise one of them have to wait. A task declares (in the task specification) entry points where it can accepts messages from other tasks. entry xyz (<parameters>) accept xyz(<parameters>) <body> (in the task body) means wait until a process P sends the message xyz, then execute <body> while P is blocked"

3 Rendezvous Time Lines Cooperation synchronization by message passing Tasks can have more than one entry point Non-deterministic choice using the select-structure: select when <villkor> => accept abc( ) or when <villkor> => accept xyz( ) end select An accept clause with a guard is either open if the guard is true closed if the guard is false a clause without a guard is always open Semantics of Tasks with Multiple accept Clauses If exactly one entry queue is nonempty, choose a message from it If more than one entry queue is nonempty, choose one, nondeterministically, from which to accept a message If all are empty, wait The construct is often called a selective wait Extended accept clause - code following the clause, but before the next clause Executed concurrently with the caller Competition synchr. implicit, only one accept clause can be active at a time 15 Semantics of select with Guarded accept Clauses: select first checks the guards on all clauses If exactly one is open, its queue is checked for messages If more than one are open, non-deterministically choose a queue among them to check for messages If all are closed, it is a runtime error A select clause can include an else clause to avoid the error When the else clause completes, the loop repeats Example: Sebesta section Concurrency in Ada 95 Ada 95 includes Ada 83 features for concurrency, plus two new features Protected objects: A more efficient way of implementing shared data to allow access to a shared data structure to be done without rendezvous. (Similar to monitors) Asynchronous communication Evaluation Semaphores are primitive but flexible, error prone. Different units cooperate on a low and detailed level. Monitors are similar to ADT:s and have similar advantages, but cooperation synchronization remains complicated. Message passing is simpler and more flexible than monitors, but still powerful, general and well-structured. Fits well with distributed systems f. 18 3

4 Java s Thread Evaluation Java s support for concurrency is relatively simple but effective Not as powerful as Ada s tasks Concurrency in C# An advance over Java threads, e.g., any method can run its own thread Thread termination is cleaner than in Java Synchronization is more sophisticated Statement-level concurrency High Performance Fortran A collection of extensions that allow the programmer to provide information to the compiler to help it optimize code for multiprocessor architectures Specify the number of processors, the distribution of data over the memories of these processors, and the alignment of data Usually several processors which executes the same code, SIMD f. 20 Statement-level concurrency Functional languages, no inherent sequentiality, different types of concurrency possible. No side effects, only data dependencies controls execution order. (Sub)expressions can be evaluated in any order, even in parallel (Church-Rosser!) No new language concepts / constructions necessary (in principle), implicit parallelism Exception handling - Basic Concepts Many languages allow programs to trap input/output errors (including EOF) An exception is any unusual event, either erroneous or not, detectable by either hardware or software, that may require special processing The special processing that may be required after detection of an exception is called exception handling The exception handling code unit is called an exception handler An exception is raised when its associated event occurs Exception handling Exception handling (cont) A program which cannot handle unusual events, exceptions isnʼt robust. We want to be able to Specify actions to be taken when an exception is detected Separate this from the main algorithm in the program Advantages Error detection code is tedious to write and clutters the program Exception handling encourages programmers to consider many different errors Exception propagation allows a high level of reuse of exception handling code Design issues: How do you define / declare an exception? Can exceptions have parameters? How is an exception activated (raised)? How do we define the units which should handle a raised exception? How is a raised exception bound to an exception handler? What is the scope of an exception handler? How (far) are exceptions propagated? Where is control transfered when a handler has finished?

5 An example: exceptions in Ada Ada, example Predefined + user defined exceptions Handlers can be bound to a block / subprogram / package / task Exceptions cannot have parameters When an exception is raised the unit is terminated, control is transfered to the handler. If there is no handler the exception is propagated to the calling unit. State-of-the-art in the 1980:s, but not without problems procedure P is BAD_FORMAT: exception; procedure Q is if S/= then raise BAD_FORMAT; end if end Q procedure R is Q; exception when BAD_FORMAT=>handler body 1 end R R; Q; exception when BAD_FORMAT=>handler body 2 end P; Exception Handling in Java Summary Based on that of C++, but more in line with OOP philosophy All exceptions are objects of classes that are descendants of the Throwable class Read by yourself (if you re not already familiar with it) The Ada design for exception handling embodies the state-of-the-art in language design in the 80:s Ada was the only widely used language with exception handling until it was added to C++ Java and ML are other languages with well developed exception handling f. 28 5

Chapter Machine instruction level 2. High-level language statement level 3. Unit level 4. Program level

Chapter 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 information

Chapter 13 Topics. Introduction. Introduction

Chapter 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 information

Chapter 13. Concurrency ISBN

Chapter 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 information

CPS 506 Comparative Programming Languages. Programming Language Paradigms

CPS 506 Comparative Programming Languages. Programming Language Paradigms CPS 506 Comparative Programming Languages Concurrent Programming Language Paradigms Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads 2 Introduction

More information

14. Exception Handling

14. Exception Handling 14. Exception Handling 14.1 Intro to Exception Handling In a language without exception handling When an exception occurs, control goes to the operating system, where a message is displayed and the program

More information

Exception Handling: Control. Exception handling is the control of error conditions or other unusual events during the execution of a program.

Exception Handling: Control. Exception handling is the control of error conditions or other unusual events during the execution of a program. Exception Handling: Control Exception handling is the control of error conditions or other unusual events during the execution of a program. 1 In a language without exception handling: When an exception

More information

Exception handling. Exceptions can be created by the hardware or by software: Examples. Printer out of paper End of page Divide by 0

Exception handling. Exceptions can be created by the hardware or by software: Examples. Printer out of paper End of page Divide by 0 Exception handling Events in a program sometimes occur at unpredictable times, I.e., apparently randomly. That is, the occurrence is an exception to the normal sequencing of events. Such events are called

More information

Performance Throughput Utilization of system resources

Performance 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 information

Chapter 14. Exception Handling and Event Handling 异常处理和事件处理. 孟小亮 Xiaoliang MENG, 答疑 ISBN

Chapter 14. Exception Handling and Event Handling 异常处理和事件处理. 孟小亮 Xiaoliang MENG, 答疑   ISBN Chapter 14 Exception Handling and Event Handling 异常处理和事件处理 孟小亮 Xiaoliang MENG, 答疑 EMAIL: 1920525866@QQ.COM ISBN 0-321-49362-1 Chapter 14 Topics Introduction to Exception Handling Exception Handling in

More information

Chapter 14. Exception Handling and Event Handling

Chapter 14. Exception Handling and Event Handling Chapter 14 Exception Handling and Event Handling Chapter 14 Topics Introduction to Exception Handling Exception Handling in Ada Exception Handling in C++ Exception Handling in Java Introduction to Event

More information

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements Programming Languages Third Edition Chapter 9 Control I Expressions and Statements Objectives Understand expressions Understand conditional statements and guards Understand loops and variation on WHILE

More information

Concurrent Programming. CS105 Programming Languages Supplement

Concurrent Programming. CS105 Programming Languages Supplement Concurrent Programming CS105 Programming Languages Supplement Outline Introduction Categories Concepts Semaphores Monitors Message Passing Statement level concurrency Introduction Definitions Process:

More information

Chapter 14. Exception Handling and Event Handling ISBN

Chapter 14. Exception Handling and Event Handling ISBN Chapter 14 Exception Handling and Event Handling ISBN 0-321-49362-1 Chapter 14 Topics Introduction to Exception Handling Exception Handling in Ada Exception Handling in C++ Exception Handling in Java Introduction

More information

CSE 130 Programming Language Principles & Paradigms Lecture # 20. Chapter 13 Concurrency. + AJAX Discussion

CSE 130 Programming Language Principles & Paradigms Lecture # 20. Chapter 13 Concurrency. + AJAX Discussion Chapter 13 Concurrency + AJAX Discussion Introduction Concurrency can occur at four levels: Machine instruction level (Processor) High-level language statement level Unit level Program level (OS) Because

More information

Concurrency - Topics. Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads

Concurrency - Topics. Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads Concurrency - Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads 1 Introduction Concurrency can occur at four levels: Machine instruction

More information

Ch 9: Control flow. Sequencers. Jumps. Jumps

Ch 9: Control flow. Sequencers. Jumps. Jumps 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

More information

Dealing with Issues for Interprocess Communication

Dealing 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 information

Resource management. Real-Time Systems. Resource management. Resource management

Resource 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 information

Chapter 5 Concurrency: Mutual Exclusion and Synchronization

Chapter 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 information

Chapter 5 Concurrency: Mutual Exclusion. and. Synchronization. Operating Systems: Internals. and. Design Principles

Chapter 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 information

Real-Time Systems. Lecture #4. Professor Jan Jonsson. Department of Computer Science and Engineering Chalmers University of Technology

Real-Time Systems. Lecture #4. Professor Jan Jonsson. Department of Computer Science and Engineering Chalmers University of Technology Real-Time Systems Lecture #4 Professor Jan Jonsson Department of Computer Science and Engineering Chalmers University of Technology Real-Time Systems Specification Resource management Mutual exclusion

More information

IT 540 Operating Systems ECE519 Advanced Operating Systems

IT 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 information

Chapter 7 Control I Expressions and Statements

Chapter 7 Control I Expressions and Statements Chapter 7 Control I Expressions and Statements Expressions Conditional Statements and Guards Loops and Variation on WHILE The GOTO Controversy Exception Handling Values and Effects Important Concepts in

More information

Process Management And Synchronization

Process 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 information

Concurrent Processes Rab Nawaz Jadoon

Concurrent Processes Rab Nawaz Jadoon Concurrent Processes Rab Nawaz Jadoon DCS COMSATS Institute of Information Technology Assistant Professor COMSATS Lahore Pakistan Operating System Concepts Concurrent Processes If more than one threads

More information

Threading and Synchronization. Fahd Albinali

Threading and Synchronization. Fahd Albinali Threading and Synchronization Fahd Albinali Parallelism Parallelism and Pseudoparallelism Why parallelize? Finding parallelism Advantages: better load balancing, better scalability Disadvantages: process/thread

More information

Process Synchronization

Process 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 information

Chapter 6: Synchronization. Operating System Concepts 8 th Edition,

Chapter 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 information

Process Synchronization: Semaphores. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

Process Synchronization: Semaphores. CSSE 332 Operating Systems Rose-Hulman Institute of Technology Process Synchronization: Semaphores CSSE 332 Operating Systems Rose-Hulman Institute of Technology Critical-section problem solution 1. Mutual Exclusion - If process Pi is executing in its critical section,

More information

Chapter 5 Asynchronous Concurrent Execution

Chapter 5 Asynchronous Concurrent Execution Chapter 5 Asynchronous Concurrent Execution Outline 5.1 Introduction 5.2 Mutual Exclusion 5.2.1 Java Multithreading Case Study 5.2.2 Critical Sections 5.2.3 Mutual Exclusion Primitives 5.3 Implementing

More information

Synchronization Principles

Synchronization 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 information

INSTITUTE OF AERONAUTICAL ENGINEERING

INSTITUTE OF AERONAUTICAL ENGINEERING INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad -500 043 INFORMATION TECHNOLOGY TUTORIAL QUESTION BANK Name : PRINCIPLES OF PROGRAMMING LANGUAGES Code : A40511 Class : II B. Tech

More information

Informatica 3. Marcello Restelli. Laurea in Ingegneria Informatica Politecnico di Milano 9/15/07 10/29/07

Informatica 3. Marcello Restelli. Laurea in Ingegneria Informatica Politecnico di Milano 9/15/07 10/29/07 Informatica 3 Marcello Restelli 9/15/07 10/29/07 Laurea in Ingegneria Informatica Politecnico di Milano Structuring the Computation Control flow can be obtained through control structure at instruction

More information

G52CON: Concepts of Concurrency Lecture 15: Message Passing. Gabriela Ochoa School of Computer Science & IT

G52CON: Concepts of Concurrency Lecture 15: Message Passing. Gabriela Ochoa School of Computer Science & IT G52CON: Concepts of Concurrency Lecture 15: Message Passing Gabriela Ochoa School of Computer Science & IT gxo@cs.nott.ac.uk Content Introduction and transition Recapitulation on hardware architectures

More information

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Operating 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 information

Lecture 9: Control Flow

Lecture 9: Control Flow Programming Languages Lecture 9: Control Flow Benjamin J. Keller Department of Computer Science, Virginia Tech Programming Languages Control Flow 2 Command Overview Assignment Control Structures Natural

More information

Interprocess Communication By: Kaushik Vaghani

Interprocess Communication By: Kaushik Vaghani Interprocess Communication By: Kaushik Vaghani Background Race Condition: A situation where several processes access and manipulate the same data concurrently and the outcome of execution depends on the

More information

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; }

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; } Semaphore Semaphore S integer variable Two standard operations modify S: wait() and signal() Originally called P() and V() Can only be accessed via two indivisible (atomic) operations wait (S) { while

More information

Synchronization: Semaphores

Synchronization: Semaphores Illinois Institute of Technology Lecture 26 4/25 solved Synchronization: Semaphores CS 536: Science of Programming, Spring 2018 A. Why Avoiding interference, while good, isn t the same as coordinating

More information

Chapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6.

Chapter 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 information

Chapter 6: Process Synchronization

Chapter 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 information

CSE 153 Design of Operating Systems Fall 2018

CSE 153 Design of Operating Systems Fall 2018 CSE 153 Design of Operating Systems Fall 2018 Lecture 5: Threads/Synchronization Implementing threads l Kernel Level Threads l u u All thread operations are implemented in the kernel The OS schedules all

More information

SYNCHRONIZATION M O D E R N O P E R A T I N G S Y S T E M S R E A D 2. 3 E X C E P T A N D S P R I N G 2018

SYNCHRONIZATION M O D E R N O P E R A T I N G S Y S T E M S R E A D 2. 3 E X C E P T A N D S P R I N G 2018 SYNCHRONIZATION M O D E R N O P E R A T I N G S Y S T E M S R E A D 2. 3 E X C E P T 2. 3. 8 A N D 2. 3. 1 0 S P R I N G 2018 INTER-PROCESS COMMUNICATION 1. How a process pass information to another process

More information

Non-blocking Array-based Algorithms for Stacks and Queues. Niloufar Shafiei

Non-blocking Array-based Algorithms for Stacks and Queues. Niloufar Shafiei Non-blocking Array-based Algorithms for Stacks and Queues Niloufar Shafiei Outline Introduction Concurrent stacks and queues Contributions New algorithms New algorithms using bounded counter values Correctness

More information

CHAPTER 6: PROCESS SYNCHRONIZATION

CHAPTER 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 information

CSE 153 Design of Operating Systems

CSE 153 Design of Operating Systems CSE 153 Design of Operating Systems Winter 19 Lecture 7/8: Synchronization (1) Administrivia How is Lab going? Be prepared with questions for this weeks Lab My impression from TAs is that you are on track

More information

Parallel And Distributed Compilers

Parallel And Distributed Compilers Parallel And Distributed Compilers Parallel Systems Parallel System has the goal to solve a given problem using multiple processors. Normally Solve a single problem These typically are used in applications

More information

Processes. Rafael Ramirez Dep Tecnologia Universitat Pompeu Fabra

Processes. Rafael Ramirez Dep Tecnologia Universitat Pompeu Fabra Processes Rafael Ramirez Dep Tecnologia Universitat Pompeu Fabra Processes Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication Process Concept Early

More information

Concurrency, 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 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 information

G52CON: Concepts of Concurrency

G52CON: Concepts of Concurrency G52CON: Concepts of Concurrency Lecture 1: Introduction Brian Logan School of Computer Science bsl@cs.nott.ac.uk Outline of this lecture" why concurrency... applications of concurrency sequential vs concurrent

More information

Structuring the Computation. Structuring the Computation

Structuring the Computation. Structuring the Computation 2016-06-10 Structuring the Computation Structuring the Computation 2016-06-10 Structuring the Computation 1 Expressions infix notation prefix notation postfix notation a (b + c) a + b c a b c + operator

More information

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs

CSE 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 information

10/17/2011. Cooperating Processes. Synchronization 1. Example: Producer Consumer (3) Example

10/17/2011. Cooperating Processes. Synchronization 1. Example: Producer Consumer (3) Example Cooperating Processes Synchronization 1 Chapter 6.1 4 processes share something (devices such as terminal, keyboard, mouse, etc., or data structures) and can affect each other non deterministic Not exactly

More information

CS370 Operating Systems

CS370 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 information

C340 Concurrency: Semaphores and Monitors. Goals

C340 Concurrency: Semaphores and Monitors. Goals C340 Concurrency: Semaphores and Monitors Wolfgang Emmerich 1 Goals Introduce concepts of Semaphores Monitors Implementation in Java synchronised methods and private attributes single thread active in

More information

Dr. D. M. Akbar Hussain DE5 Department of Electronic Systems

Dr. 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 information

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad-00 014 Subject: PPL Class : CSE III 1 P a g e DEPARTMENT COMPUTER SCIENCE AND ENGINEERING S No QUESTION Blooms Course taxonomy level Outcomes UNIT-I

More information

CSE332: Data Abstractions Lecture 22: Shared-Memory Concurrency and Mutual Exclusion. Tyler Robison Summer 2010

CSE332: Data Abstractions Lecture 22: Shared-Memory Concurrency and Mutual Exclusion. Tyler Robison Summer 2010 CSE332: Data Abstractions Lecture 22: Shared-Memory Concurrency and Mutual Exclusion Tyler Robison Summer 2010 1 Toward sharing resources (memory) So far we ve looked at parallel algorithms using fork-join

More information

CS 153 Design of Operating Systems Winter 2016

CS 153 Design of Operating Systems Winter 2016 CS 153 Design of Operating Systems Winter 2016 Lecture 7: Synchronization Administrivia Homework 1 Due today by the end of day Hopefully you have started on project 1 by now? Kernel-level threads (preemptable

More information

Defensive Programming

Defensive Programming Copyright R.A. van Engelen, FSU Department of Computer Science, 2000 Exception Handling In this set of notes you will learn about: Defensive programming Ways to catch and handle run-time errors without

More information

Synchronization I. Jo, Heeseung

Synchronization 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 information

Last Class: Synchronization

Last Class: Synchronization Last Class: Synchronization Synchronization primitives are required to ensure that only one thread executes in a critical section at a time. Concurrent programs Low-level atomic operations (hardware) load/store

More information

G52CON: Concepts of Concurrency

G52CON: Concepts of Concurrency G52CON: Concepts of Concurrency Lecture 4: Atomic Actions Natasha Alechina School of Computer Science nza@cs.nott.ac.uk Outline of the lecture process execution fine-grained atomic actions using fine-grained

More information

G Programming Languages Spring 2010 Lecture 13. Robert Grimm, New York University

G 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 information

IV. Process Synchronisation

IV. 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 information

Process Synchronisation (contd.) Operating Systems. Autumn CS4023

Process 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 information

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Hank Levy 412 Sieg Hall

CSE 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 information

CSE Traditional Operating Systems deal with typical system software designed to be:

CSE Traditional Operating Systems deal with typical system software designed to be: CSE 6431 Traditional Operating Systems deal with typical system software designed to be: general purpose running on single processor machines Advanced Operating Systems are designed for either a special

More information

ENGR 3950U / CSCI 3020U UOIT, Fall 2012 Quiz on Process Synchronization SOLUTIONS

ENGR 3950U / CSCI 3020U UOIT, Fall 2012 Quiz on Process Synchronization SOLUTIONS Name: Student Number: SOLUTIONS ENGR 3950U / CSCI 3020U (Operating Systems) Quiz on Process Synchronization November 13, 2012, Duration: 40 Minutes (10 questions and 8 pages, 45 Marks) Instructor: Dr.

More information

Models of concurrency & synchronization algorithms

Models 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 information

Chapter 6: Process Synchronization

Chapter 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 information

*uuumuuuuuum// EIIIIIEEIIIE- ll~~llllll IIIIIIIIIENI. ll~~lllllllii

*uuumuuuuuum// EIIIIIEEIIIE- ll~~llllll IIIIIIIIIENI. ll~~lllllllii AD-AIIO 920 STANFORD UNIV CA DEPT OF COMPUTER SCIENCE F/G 9/2 ADAM - AN ADA BASED LANGUAGE FOR MULTI-PROCESSING.(U) JUL 81 D C LUCKHAM, H J LARSEN, D R STEVENSON MDA9OI3"-C-0159 UNCLASSIFIED STAN-CS-81-867

More information

Concurrency: Mutual Exclusion and Synchronization. Concurrency

Concurrency: Mutual Exclusion and Synchronization. Concurrency Concurrency: Mutual Exclusion and Synchronization Chapter 5 1 Concurrency Multiple applications Structured applications Operating system structure 2 1 Concurrency 3 Difficulties of Concurrency Sharing

More information

Concurrent Programming

Concurrent 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 information

Concurrency Control. Synchronization. Brief Preview of Scheduling. Motivating Example. Motivating Example (Cont d) Interleaved Schedules

Concurrency 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 information

Overview. Lab advice. Lab advice. Readers-writers problem. Readers-writers solution. Real-time Systems D0003E 3/10/2009

Overview. Lab advice. Lab advice. Readers-writers problem. Readers-writers solution. Real-time Systems D0003E 3/10/2009 Overview Real-time Systems D0003E Lecture 14: Real-time languages (Burns & Wellings ch. 8 & 9) A little lab advice Generic parking Synchronization semaphores readers-writers problem monitors guards (ccr:s)

More information

Lecture 9: Parameter Passing, Generics and Polymorphism, Exceptions

Lecture 9: Parameter Passing, Generics and Polymorphism, Exceptions Lecture 9: Parameter Passing, Generics and Polymorphism, Exceptions COMP 524 Programming Language Concepts Stephen Olivier February 12, 2008 Based on notes by A. Block, N. Fisher, F. Hernandez-Campos,

More information

Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017

Operating 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 information

Multitasking / Multithreading system Supports multiple tasks

Multitasking / Multithreading system Supports multiple tasks Tasks and Intertask Communication Introduction Multitasking / Multithreading system Supports multiple tasks As we ve noted Important job in multitasking system Exchanging data between tasks Synchronizing

More information

Copyright 2008 CS655 System Modeling and Analysis. Korea Advanced Institute of Science and Technology

Copyright 2008 CS655 System Modeling and Analysis. Korea Advanced Institute of Science and Technology The Spin Model Checker : Part I Copyright 2008 CS655 System Korea Advanced Institute of Science and Technology System Spec. In Promela Req. Spec. In LTL Overview of the Spin Architecture Spin Model pan.c

More information

2. The system of... generally ran one job at a time. These were called single stream batch processing.

2. The system of... generally ran one job at a time. These were called single stream batch processing. Set 1 1. Which of the following is/ are the part of operating system? A) Kernel services B) Library services C) Application level services D) All of the above 2. The system of... generally ran one job

More information

Chapter 7: Process Synchronization!

Chapter 7: Process Synchronization! Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Monitors 7.1 Background Concurrent access to shared

More information

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring 2002

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring 2002 CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring 2002 Lecture 6: Synchronization 6.0 Main points More concurrency examples Synchronization primitives 6.1 A Larger Concurrent

More information

Background. Module 6: Process Synchronization. Bounded-Buffer (Cont.) Bounded-Buffer. Background

Background. Module 6: Process Synchronization. Bounded-Buffer (Cont.) Bounded-Buffer. Background Module 6: Process Synchronization Background Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Critical Regions Monitors Synchronization

More information

Synchronization I. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Synchronization 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 information

Programming Languages

Programming Languages Programming Languages Tevfik Koşar Lecture - XXVII May 2 nd, 2006 1 Roadmap Shared Memory Cigarette Smokers Problem Monitors Message Passing Cooperative Operations Synchronous and Asynchronous Sends Blocking

More information

Java Threads. COMP 585 Noteset #2 1

Java 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

Synchronization. Silvina Hanono Wachman Computer Science & Artificial Intelligence Lab M.I.T.

Synchronization. Silvina Hanono Wachman Computer Science & Artificial Intelligence Lab M.I.T. Synchronization Silvina Hanono Wachman Computer Science & Artificial Intelligence Lab M.I.T. L24-1 Reminders All labs must be completed by this Friday, Dec. 7 th to pass the course Any work you intend

More information

Concurrent Programming

Concurrent Programming Concurrent Programming Yuh-Jzer Joung Dept. of Information Management National Taiwan University May, 2001 CONCURRENT PROGRAMMING Operations in the source text are concurrent if they could be, but need

More information

General Objectives: To understand the process management in operating system. Specific Objectives: At the end of the unit you should be able to:

General 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 information

Concurrency: a crash course

Concurrency: 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 information

COP4020 Programming Languages. Exception Handling Prof. Robert van Engelen

COP4020 Programming Languages. Exception Handling Prof. Robert van Engelen COP4020 Programming Languages Exception Handling Prof. Robert van Engelen Overview What is defensive programming? Ways to catch and handle run-time errors: In programming languages that do not support

More information

G52CON: Concepts of Concurrency

G52CON: Concepts of Concurrency G52CON: Concepts of Concurrency Lecture 6: Algorithms for Mutual Natasha Alechina School of Computer Science nza@cs.nott.ac.uk Outline of this lecture mutual exclusion with standard instructions example:

More information

What's wrong with Semaphores?

What's wrong with Semaphores? Next: Monitors and Condition Variables What is wrong with semaphores? Monitors What are they? How do we implement monitors? Two types of monitors: Mesa and Hoare Compare semaphore and monitors Lecture

More information

1 Process Coordination

1 Process Coordination COMP 730 (242) Class Notes Section 5: Process Coordination 1 Process Coordination Process coordination consists of synchronization and mutual exclusion, which were discussed earlier. We will now study

More information

The S-Expression Design Language (SEDL) James C. Corbett. September 1, Introduction. 2 Origins of SEDL 2. 3 The Language SEDL 2.

The S-Expression Design Language (SEDL) James C. Corbett. September 1, Introduction. 2 Origins of SEDL 2. 3 The Language SEDL 2. The S-Expression Design Language (SEDL) James C. Corbett September 1, 1993 Contents 1 Introduction 1 2 Origins of SEDL 2 3 The Language SEDL 2 3.1 Scopes : : : : : : : : : : : : : : : : : : : : : : : :

More information

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA.

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA. R13 SET - 1 III B. Tech I Semester Regular Examinations, November - 2015 1 a) What constitutes a programming environment? [3M] b) What mixed-mode assignments are allowed in C and Java? [4M] c) What is

More information

Process Synchronization

Process Synchronization Chapter 7 Process Synchronization 1 Chapter s Content Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Critical Regions Monitors 2 Background

More information

Summary Semaphores. Passing the Baton any await statement. Synchronisation code not linked to the data

Summary Semaphores. Passing the Baton any await statement. Synchronisation code not linked to the data Lecture 4 Monitors Summary Semaphores Good news Simple, efficient, expressive Passing the Baton any await statement Bad news Low level, unstructured omit a V: deadlock omit a P: failure of mutex Synchronisation

More information

Synchronization. Race Condition. The Critical-Section Problem Solution. The Synchronization Problem. Typical Process P i. Peterson s Solution

Synchronization. Race Condition. The Critical-Section Problem Solution. The Synchronization Problem. Typical Process P i. Peterson s Solution Race Condition Synchronization CSCI 315 Operating Systems Design Department of Computer Science A race occurs when the correctness of a program depends on one thread reaching point x in its control flow

More information