News and remarks. CS68 Principles of Programming Languages. Contents today. Concurrency. Declarative concurrency. Threads

Size: px
Start display at page:

Download "News and remarks. CS68 Principles of Programming Languages. Contents today. Concurrency. Declarative concurrency. Threads"

Transcription

1 News and remarks CS68 Principles of Programming Languages Håkan Jonsson Dept of Computer Science and Electrical Engineering Luleå University of Technology, Sweden and Computer Science, Dartmouth College Apart from the Oz Browser there is a also the Oz Panel that shows runtime information. Open the Oz panel from emacs: Either menu option, or C-. C-. s Extra help on HW2 posted in Blackboard. A version of ToHTML to test your Parse. The label "doc" and the parenthesis surrounding the list in 2a and 2b should not be there(!) The list should be the sole input to Parse. doc([ ]) should be [ ] October 15, 2007 CS68 Lecture 9 - Håkan Jonsson Page 2 Contents today Declarative concurrency. Threads October 15, 2007 CS68 Lecture 9 - Håkan Jonsson Page 3 Concurrency By concurrency is meant that several activities executes simultaneously. Network and disk I/O, multiple processes, unix pipelines, The Search for Extra- Terrestrial Intelligence (SETI), etc. Concurrency in programming enables us to organize our programs into indepent parts. Crucial questions: How are actions synchronized? How are data communicated? In Oz, concurrency is achieved by means of threads. The basic syntax is: thread <S> Informal semantics: Evaluate <S> in a separate thread; execution of the main program (and other threads) continues while <S> is being evaluated. Examples: Delay and Cmap. October 15, 2007 CS68 Lecture 9 - Håkan Jonsson Page 4

2 Concurrency Each thread is executed as a single program. Same semantics as we have already seen. In fact, all programs we have seen so far have been executed as a (single) thread. The meaning of the simultaneous execution of several threads is explained in terms of an execution state with multiple semantic stacks (one per thread) that all share the same single-assignment store. Multiple reads can happen truly simultaneously. Multiple writes happen in some order. Depencies among threads induce constraints upon order of execution, but otherwise the order in which statements execute across threads is undetermined. Example: CFib Fibonacci with threads October 15, 2007 CS68 Lecture 9 - Håkan Jonsson Page 5 October 15, 2007 CS68 Lecture 9 - Håkan Jonsson Page 6 Execution of threads Thread semantics Formally speaking, the abstract machine model is exted. Executions states will have a multi-set MST of semantics stacks. One stack per thread. A multi-set is a set in which an element can occur more than once (multi-sets are also called bags). Machine state: (MST,!) where MST={ST1,ST2,,STn} is a multi-set and! a singleassignment store. October 15, 2007 CS68 Lecture 9 - Håkan Jonsson Page 7 October 15, 2007 CS68 Lecture 9 - Håkan Jonsson Page 8

3 Thread semantics Execution semantics: Let (MST,!) be the execution state. Then, if all stacks of MST are empty, halt. The program has now terminated. Otherwise, wait until at least one element of MST is runnable. This could, but must not be, an indefinite wait. Choose a runnable stack ST from MST. Let MST' = MST \ {ST}. Pop the top element (<S>,E) of ST and evaluate it according to the rules. This gives a new stack ST and a new store!. Let (MST' " {ST'},! ) be the new machine state. Redo. Notice that all active stacks share a single-assignment store. The semantics describe an implementation that will work on a 1-processor computer, but permit execution by a true multiprocessor. October 15, 2007 CS68 Lecture 9 - Håkan Jonsson Page 9 Scheduling Ideally, threads should seem like running concurrently, even if we are simulating concurrency on a single processor system. The way a runnable thread is chosen affects this. If we choose "unfairly", some threads may seem like not running at all (or much slower than needed/expected). Starvation: A thread is runnable, but never gets chosen. Fair: Every runnable thread will eventually be chosen. Typical scheduling approaches: Time slicing using timers (could be hardware interrupts) and priority levels. Dead-lock, all threads susped: thread 1 is susped on X; next line of code will bind Y. thread 2 is susped on Y; next line of code will bind X. October 15, 2007 CS68 Lecture 9 - Håkan Jonsson Page 10 Order of execution October 15, 2007 CS68 Lecture 9 - Håkan Jonsson Page 11 Easy separation of tasks Example 1: In a client for a MMORPG (Massively Multiplayer Online Role Playing Game) we could put the graphics computation, the networking processing, the internal modeling (computing what actually happens, making predictions, and coping with uncertain information), and the interaction with the player in separate threads. Problem: Balancing the share of processor power given to each thread so that the game becomes realistic. Without threads a program like this could be programmed as a single loop in which all task are carried out in sequence. This doesn t work in practice since some operations might block and others take unacceptable long to complete (causing others to wait). In the concurrent declarative model, breaking up a sequential program into threads gives a program with an equivalent semantics but, possibly, with another order of execution. October 15, 2007 CS68 Lecture 9 - Håkan Jonsson Page 12

4 Coroutines: Many applications can be modeled as communicating sequential processes. A coroutine is a component much like a procedure that runs forever once started and that every now and then transfers control to other co-routines and goes to sleep until control is returned. A coroutine decides on its own when to run or not. Communication is crucial between coroutines. Typical applications are so called producer - consumer and client -server applications. Example October 15, 2007 CS68 Lecture 9 - Håkan Jonsson Page 13 Table 4.2 This example makes use of the Thread module. Drawback: Threads need to know about each other. The activation and suspension of threads must be programmed. Next lecture we will learn about other, better, ways to produce clientserver and producer-consumer applications. October 15, 2007 CS68 Lecture 9 - Håkan Jonsson Page 14 Components We know how to start a thread; but how do we wait for a thread to finish? Solution: Create an unbound variable Done, In thread 1: Bind Done at exit. In thread 2: Call {Wait Done} to wait until Done is bound. Wait is easy to implement: proc {Wait V} case V of x then skip else skip October 15, 2007 CS68 Lecture 9 - Håkan Jonsson Page 15 October 15, 2007 CS68 Lecture 9 - Håkan Jonsson Page 16

5 This idea generalizes to multiple threads; either call Wait many times, or introduce multiple variables: local T 1 T 2 T n in thread T 1 = done thread T 2 = T 1 thread T n = T n-1 {Wait T n } Notice how this "cascades ; each thread waits for the previous ones to bind their variable (and terminate). More generally, this synchronizes n threads, executing a procedure each, so they all finish before Barrier returns: Creates a new thread each recursive step. {Barrier [ proc {$} <stmt> 1 proc {$} <stmt> 2... proc {$} <stmt> n ] } proc {Barrier Ps} fun {BarrierLoop Ps L} case Ps of P Pr then M in thread {P} M=L {BarrierLoop Pr M} [] nil then L S={BarrierLoop Ps unit} in {Wait S} Creates a new unbound variable each recursive step. October 15, 2007 CS68 Lecture 9 - Håkan Jonsson Page 17 October 15, 2007 CS68 Lecture 9 - Håkan Jonsson Page 18 Nondeterminism If there are more than one thread that can bind a variable we have observable nondeterminism. The meaning of such a program deps on which binding is carried out first. This is not decided by the programming language but deps on the policy of the thread scheduler. Example Next lecture (Wednesday) Homework 2 due. Read Ch. 4.3 October 15, 2007 CS68 Lecture 9 - Håkan Jonsson Page 19 October 15, 2007 CS68 Lecture 9 - Håkan Jonsson Page 20

Programming Language Concepts, cs2104 Lecture 09 ( )

Programming Language Concepts, cs2104 Lecture 09 ( ) Programming Language Concepts, cs2104 Lecture 09 (2003-10-10) Seif Haridi Department of Computer Science, NUS haridi@comp.nus.edu.sg 2003-10-03 S. Haridi, CS2104, L09 (slides: C. Schulte, S. Haridi) 1

More information

Declarative Concurrency (CTM 4)

Declarative Concurrency (CTM 4) Declarative Concurrency (CTM 4) Carlos Varela Rensselaer Polytechnic Institute Adapted with permission from: Seif Haridi KTH Peter Van Roy UCL November 21, 2014 C. Varela; Adapted with permission from

More information

Declarative Concurrency (CTM 4)

Declarative Concurrency (CTM 4) Declarative Concurrency (CTM 4) Carlos Varela Rensselaer Polytechnic Institute Adapted with permission from: Seif Haridi KTH Peter Van Roy UCL October 30, 2015 C. Varela; Adapted with permission from S.

More information

Lecture 5: Declarative Programming. The Declarative Kernel Language Machine. September 12th, 2011

Lecture 5: Declarative Programming. The Declarative Kernel Language Machine. September 12th, 2011 Lecture 5: Declarative Programming. The Declarative Kernel Language Machine September 12th, 2011 1 Lecture Outline Declarative Programming contd Dataflow Variables contd Expressions and Statements Functions

More information

CSE 120 Principles of Operating Systems

CSE 120 Principles of Operating Systems CSE 120 Principles of Operating Systems Fall 2015 Lecture 4: Threads Geoffrey M. Voelker Announcements Project 0 due Project 1 out October 6, 2015 CSE 120 Lecture 4 Threads 2 Processes Recall that a process

More information

Processes and Non-Preemptive Scheduling. Otto J. Anshus

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

Lecture 6: The Declarative Kernel Language Machine. September 13th, 2011

Lecture 6: The Declarative Kernel Language Machine. September 13th, 2011 Lecture 6: The Declarative Kernel Language Machine September 13th, 2011 Lecture Outline Computations contd Execution of Non-Freezable Statements on the Abstract Machine The skip Statement The Sequential

More information

Programming Language Concepts, cs2104 Lecture 04 ( )

Programming Language Concepts, cs2104 Lecture 04 ( ) Programming Language Concepts, cs2104 Lecture 04 (2003-08-29) Seif Haridi Department of Computer Science, NUS haridi@comp.nus.edu.sg 2003-09-05 S. Haridi, CS2104, L04 (slides: C. Schulte, S. Haridi) 1

More information

News and information! Review: Java Programs! Feedback after Lecture 2! Dead-lines for the first two lab assignment have been posted.!

News and information! Review: Java Programs! Feedback after Lecture 2! Dead-lines for the first two lab assignment have been posted.! True object-oriented programming: Dynamic Objects Reference Variables D0010E Object-Oriented Programming and Design Lecture 3 Static Object-Oriented Programming UML" knows-about Eckel: 30-31, 41-46, 107-111,

More information

Last Class: CPU Scheduling! Adjusting Priorities in MLFQ!

Last Class: CPU Scheduling! Adjusting Priorities in MLFQ! Last Class: CPU Scheduling! Scheduling Algorithms: FCFS Round Robin SJF Multilevel Feedback Queues Lottery Scheduling Review questions: How does each work? Advantages? Disadvantages? Lecture 7, page 1

More information

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

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring 2004 CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring 2004 Lecture 9: Readers-Writers and Language Support for Synchronization 9.1.2 Constraints 1. Readers can access database

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

CMSC 132: Object-Oriented Programming II. Threads in Java

CMSC 132: Object-Oriented Programming II. Threads in Java CMSC 132: Object-Oriented Programming II Threads in Java 1 Problem Multiple tasks for computer Draw & display images on screen Check keyboard & mouse input Send & receive data on network Read & write files

More information

Declarative Computation Model

Declarative Computation Model Declarative Computation Model Kernel language semantics revisited (VRH 2.4.5) From kernel to practical language (VRH 2.6) Exceptions (VRH 2.7) Carlos Varela RPI March 19, 2012 Adapted with permission from:

More information

Computer System Overview

Computer System Overview Computer System Overview Introduction A computer system consists of hardware system programs application programs 2 Operating System Provides a set of services to system users (collection of service programs)

More information

Midterm Exam Amy Murphy 19 March 2003

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

CS140 Operating Systems Midterm Review. Feb. 5 th, 2009 Derrick Isaacson

CS140 Operating Systems Midterm Review. Feb. 5 th, 2009 Derrick Isaacson CS140 Operating Systems Midterm Review Feb. 5 th, 2009 Derrick Isaacson Midterm Quiz Tues. Feb. 10 th In class (4:15-5:30 Skilling) Open book, open notes (closed laptop) Bring printouts You won t have

More information

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems Processes CS 475, Spring 2018 Concurrent & Distributed Systems Review: Abstractions 2 Review: Concurrency & Parallelism 4 different things: T1 T2 T3 T4 Concurrency: (1 processor) Time T1 T2 T3 T4 T1 T1

More information

Lecture Topics. Announcements. Today: Uniprocessor Scheduling (Stallings, chapter ) Next: Advanced Scheduling (Stallings, chapter

Lecture Topics. Announcements. Today: Uniprocessor Scheduling (Stallings, chapter ) Next: Advanced Scheduling (Stallings, chapter Lecture Topics Today: Uniprocessor Scheduling (Stallings, chapter 9.1-9.3) Next: Advanced Scheduling (Stallings, chapter 10.1-10.4) 1 Announcements Self-Study Exercise #10 Project #8 (due 11/16) Project

More information

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017 CS 471 Operating Systems Yue Cheng George Mason University Fall 2017 Outline o Process concept o Process creation o Process states and scheduling o Preemption and context switch o Inter-process communication

More information

Lecture 21: Relational Programming II. November 15th, 2011

Lecture 21: Relational Programming II. November 15th, 2011 Lecture 21: Relational Programming II November 15th, 2011 Lecture Outline Relational Programming contd The Relational Model of Computation Programming with choice and Solve Search Strategies Relational

More information

What s An OS? Cyclic Executive. Interrupts. Advantages Simple implementation Low overhead Very predictable

What s An OS? Cyclic Executive. Interrupts. Advantages Simple implementation Low overhead Very predictable What s An OS? Provides environment for executing programs Process abstraction for multitasking/concurrency scheduling Hardware abstraction layer (device drivers) File systems Communication Do we need an

More information

Lecture 4: Threads; weaving control flow

Lecture 4: Threads; weaving control flow Lecture 4: Threads; weaving control flow CSE 120: Principles of Operating Systems Alex C. Snoeren HW 1 Due NOW Announcements Homework #1 due now Project 0 due tonight Project groups Please send project

More information

CS370 Operating Systems Midterm Review

CS370 Operating Systems Midterm Review CS370 Operating Systems Midterm Review Yashwant K Malaiya Fall 2015 Slides based on Text by Silberschatz, Galvin, Gagne 1 1 What is an Operating System? An OS is a program that acts an intermediary between

More information

SPIN, PETERSON AND BAKERY LOCKS

SPIN, PETERSON AND BAKERY LOCKS Concurrent Programs reasoning about their execution proving correctness start by considering execution sequences CS4021/4521 2018 jones@scss.tcd.ie School of Computer Science and Statistics, Trinity College

More information

Lecture 4: The Declarative Sequential Kernel Language. September 5th 2011

Lecture 4: The Declarative Sequential Kernel Language. September 5th 2011 Lecture 4: The Declarative Sequential Kernel Language September 5th 2011 1 Lecture Outline Syntactic Analysis of Programs contd Scanning contd The Declarative Kernel Language Introduction Syntax of the

More information

Mozart System Limitations for Version (draft)

Mozart System Limitations for Version (draft) Mozart System Limitations for Version 1.3.0 (draft) Peter Van Roy and Seif Haridi April 28, 2004 In der Beschränkung zeigt sich erst der Meister. Within limitations the Master is first revealed. Johann

More information

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

Exam for 2G1512 DatalogiII, Apr 12th

Exam for 2G1512 DatalogiII, Apr 12th Exam for 2G1512 DatalogiII, Apr 12th 2002 09.00 14.00 Dept. of Microelectronics and Information Technology April 11, 2002 Allowed materials You are allowed to bring the course book and all handouts to

More information

CS3733: Operating Systems

CS3733: Operating Systems Outline CS3733: Operating Systems Topics: Synchronization, Critical Sections and Semaphores (SGG Chapter 6) Instructor: Dr. Tongping Liu 1 Memory Model of Multithreaded Programs Synchronization for coordinated

More information

Announcement. Exercise #2 will be out today. Due date is next Monday

Announcement. Exercise #2 will be out today. Due date is next Monday Announcement Exercise #2 will be out today Due date is next Monday Major OS Developments 2 Evolution of Operating Systems Generations include: Serial Processing Simple Batch Systems Multiprogrammed Batch

More information

Course Syllabus. Operating Systems

Course Syllabus. Operating Systems Course Syllabus. Introduction - History; Views; Concepts; Structure 2. Process Management - Processes; State + Resources; Threads; Unix implementation of Processes 3. Scheduling Paradigms; Unix; Modeling

More information

Implementation of Process Networks in Java

Implementation of Process Networks in Java Implementation of Process Networks in Java Richard S, Stevens 1, Marlene Wan, Peggy Laramie, Thomas M. Parks, Edward A. Lee DRAFT: 10 July 1997 Abstract A process network, as described by G. Kahn, is a

More information

Synchronization. Before We Begin. Synchronization. Credit/Debit Problem: Race Condition. CSE 120: Principles of Operating Systems.

Synchronization. Before We Begin. Synchronization. Credit/Debit Problem: Race Condition. CSE 120: Principles of Operating Systems. CSE 120: Principles of Operating Systems Lecture 4 Synchronization January 23, 2006 Prof. Joe Pasquale Department of Computer Science and Engineering University of California, San Diego Before We Begin

More information

Lecture 4: Memory Management & The Programming Interface

Lecture 4: Memory Management & The Programming Interface CS 422/522 Design & Implementation of Operating Systems Lecture 4: Memory Management & The Programming Interface Zhong Shao Dept. of Computer Science Yale University Acknowledgement: some slides are taken

More information

Advanced Operating Systems (CS 202) Scheduling (1)

Advanced Operating Systems (CS 202) Scheduling (1) Advanced Operating Systems (CS 202) Scheduling (1) Today: CPU Scheduling 2 The Process The process is the OS abstraction for execution It is the unit of execution It is the unit of scheduling It is the

More information

CS 318 Principles of Operating Systems

CS 318 Principles of Operating Systems CS 318 Principles of Operating Systems Fall 2018 Lecture 4: Scheduling Ryan Huang Slides adapted from David Mazières lectures Administrivia Lab 0 Due today Submit in Blackboard Lab 1 released Due in two

More information

Operating Systems. Process scheduling. Thomas Ropars.

Operating Systems. Process scheduling. Thomas Ropars. 1 Operating Systems Process scheduling Thomas Ropars thomas.ropars@univ-grenoble-alpes.fr 2018 References The content of these lectures is inspired by: The lecture notes of Renaud Lachaize. The lecture

More information

Notes based on prof. Morris's lecture on scheduling (6.824, fall'02).

Notes based on prof. Morris's lecture on scheduling (6.824, fall'02). Scheduling Required reading: Eliminating receive livelock Notes based on prof. Morris's lecture on scheduling (6.824, fall'02). Overview What is scheduling? The OS policies and mechanisms to allocates

More information

6.033 Computer System Engineering

6.033 Computer System Engineering MIT OpenCourseWare http://ocw.mit.edu 6.033 Computer System Engineering Spring 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. 6.003 Lecture 7: Threads

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

Process Scheduling. Copyright : University of Illinois CS 241 Staff

Process Scheduling. Copyright : University of Illinois CS 241 Staff Process Scheduling Copyright : University of Illinois CS 241 Staff 1 Process Scheduling Deciding which process/thread should occupy the resource (CPU, disk, etc) CPU I want to play Whose turn is it? Process

More information

238P: Operating Systems. Lecture 14: Process scheduling

238P: Operating Systems. Lecture 14: Process scheduling 238P: Operating Systems Lecture 14: Process scheduling This lecture is heavily based on the material developed by Don Porter Anton Burtsev November, 2017 Cooperative vs preemptive What is cooperative multitasking?

More information

Written Presentation: JoCaml, a Language for Concurrent Distributed and Mobile Programming

Written Presentation: JoCaml, a Language for Concurrent Distributed and Mobile Programming Written Presentation: JoCaml, a Language for Concurrent Distributed and Mobile Programming Nicolas Bettenburg 1 Universitaet des Saarlandes, D-66041 Saarbruecken, nicbet@studcs.uni-sb.de Abstract. As traditional

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Values and Types We divide the universe of values according to types A type is a set of values and

More information

cs Java: lecture #6

cs Java: lecture #6 cs3101-003 Java: lecture #6 news: homework #5 due today little quiz today it s the last class! please return any textbooks you borrowed from me today s topics: interfaces recursion data structures threads

More information

Lock-Free and Practical Doubly Linked List-Based Deques using Single-Word Compare-And-Swap

Lock-Free and Practical Doubly Linked List-Based Deques using Single-Word Compare-And-Swap Lock-Free and Practical Doubly Linked List-Based Deques using Single-Word Compare-And-Swap Håkan Sundell Philippas Tsigas OPODIS 2004: The 8th International Conference on Principles of Distributed Systems

More information

Process Description and Control

Process Description and Control Process Description and Control 1 Process:the concept Process = a program in execution Example processes: OS kernel OS shell Program executing after compilation www-browser Process management by OS : Allocate

More information

CSE 120 Principles of Operating Systems

CSE 120 Principles of Operating Systems CSE 120 Principles of Operating Systems Spring 2009 Lecture 4: Threads Geoffrey M. Voelker Announcements Homework #1 due now Project 0 due tonight Project 1 out April 9, 2009 CSE 120 Lecture 4 Threads

More information

Le L c e t c ur u e e 7 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Multithreading

Le L c e t c ur u e e 7 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Multithreading Course Name: Advanced Java Lecture 7 Topics to be covered Multithreading Thread--An Introduction Thread A thread is defined as the path of execution of a program. It is a sequence of instructions that

More information

UNIT:2. Process Management

UNIT:2. Process Management 1 UNIT:2 Process Management SYLLABUS 2.1 Process and Process management i. Process model overview ii. Programmers view of process iii. Process states 2.2 Process and Processor Scheduling i Scheduling Criteria

More information

ECE 574 Cluster Computing Lecture 8

ECE 574 Cluster Computing Lecture 8 ECE 574 Cluster Computing Lecture 8 Vince Weaver http://web.eece.maine.edu/~vweaver vincent.weaver@maine.edu 16 February 2017 Announcements Too many snow days Posted a video with HW#4 Review HW#5 will

More information

Concurrency. Chapter 5

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

Lecture 2: Intro to Concurrent Processing. A Model of Concurrent Programming

Lecture 2: Intro to Concurrent Processing. A Model of Concurrent Programming Lecture 2: Intro to Concurrent Processing The SR Language. Correctness and Concurrency. Mutual Exclusion & Critical Sections. Software Solutions to Mutual Exclusion. Dekker s Algorithm. The Bakery Algorithm.

More information

Today: Synchronization. Recap: Synchronization

Today: Synchronization. Recap: Synchronization Today: Synchronization Synchronization Mutual exclusion Critical sections Example: Too Much Milk Locks Synchronization primitives are required to ensure that only one thread executes in a critical section

More information

Multi-Level Feedback Queues

Multi-Level Feedback Queues CS 326: Operating Systems Multi-Level Feedback Queues Lecture 8 Today s Schedule Building an Ideal Scheduler Priority-Based Scheduling Multi-Level Queues Multi-Level Feedback Queues Scheduling Domains

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

Concurrency Terminology

Concurrency Terminology Lesson 1 Concurrency Ch 1 [BenA 06] Terminology Concurrency in Systems Problem Examples Solution Considerations 1 Concurrency Terminology Process, thread tavallinen ohjelma Ordinary program Sequential

More information

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

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

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved. Processes Prof. James L. Frankel Harvard University Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved. Process Model Each process consists of a sequential program

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

ò mm_struct represents an address space in kernel ò task represents a thread in the kernel ò A task points to 0 or 1 mm_structs

ò mm_struct represents an address space in kernel ò task represents a thread in the kernel ò A task points to 0 or 1 mm_structs Last time We went through the high-level theory of scheduling algorithms Scheduling Today: View into how Linux makes its scheduling decisions Don Porter CSE 306 Lecture goals Understand low-level building

More information

Lecture 2: Intro to Concurrent Processing

Lecture 2: Intro to Concurrent Processing Lecture 2: Intro to Concurrent Processing The SR Language. Correctness and Concurrency. Mutual Exclusion & Critical Sections. Software Solutions to Mutual Exclusion. Dekker s Algorithm. The Bakery Algorithm.

More information

Lecture 4: Inter-Process Communication (Jan 27, 2005)

Lecture 4: Inter-Process Communication (Jan 27, 2005) Lecture 4: Inter-Process Communication (Jan 27, 2005) February 17, 2005 1 Review Q: What is the other command that seems to go hand-in-hand with fork()? A: exec* (6 variants of this command) Q: Suppose

More information

CSCI-GA Operating Systems Lecture 3: Processes and Threads -Part 2 Scheduling Hubertus Franke

CSCI-GA Operating Systems Lecture 3: Processes and Threads -Part 2 Scheduling Hubertus Franke CSCI-GA.2250-001 Operating Systems Lecture 3: Processes and Threads -Part 2 Scheduling Hubertus Franke frankeh@cs.nyu.edu Processes Vs Threads The unit of dispatching is referred to as a thread or lightweight

More information

Scheduling. Don Porter CSE 306

Scheduling. Don Porter CSE 306 Scheduling Don Porter CSE 306 Last time ò We went through the high-level theory of scheduling algorithms ò Today: View into how Linux makes its scheduling decisions Lecture goals ò Understand low-level

More information

Lecture Topics. Announcements. Today: Concurrency: Mutual Exclusion (Stallings, chapter , 5.7)

Lecture Topics. Announcements. Today: Concurrency: Mutual Exclusion (Stallings, chapter , 5.7) Lecture Topics Today: Concurrency: Mutual Exclusion (Stallings, chapter 5.1-5.4, 5.7) Next: Concurrency: Deadlock and Starvation (Stallings, chapter 6.1, 6.6-6.8) 1 Announcements Self-Study Exercise #5

More information

Concurrent and Distributed Systems Introduction

Concurrent and Distributed Systems Introduction Concurrent and Distributed Systems 8 lectures on concurrency control in centralised systems - interaction of components in main memory - interactions involving main memory and persistent storage (concurrency

More information

CSE 153 Design of Operating Systems

CSE 153 Design of Operating Systems CSE 153 Design of Operating Systems Winter 2018 Lecture 10: Monitors Monitors A monitor is a programming language construct that controls access to shared data Synchronization code added by compiler, enforced

More information

Yi Shi Fall 2017 Xi an Jiaotong University

Yi Shi Fall 2017 Xi an Jiaotong University Threads Yi Shi Fall 2017 Xi an Jiaotong University Goals for Today Case for Threads Thread details Case for Parallelism main() read_data() for(all data) compute(); write_data(); endfor main() read_data()

More information

MultiThreading. Object Orientated Programming in Java. Benjamin Kenwright

MultiThreading. Object Orientated Programming in Java. Benjamin Kenwright MultiThreading Object Orientated Programming in Java Benjamin Kenwright Outline Review Essential Java Multithreading Examples Today s Practical Review/Discussion Question Does the following code compile?

More information

CS4215 Programming Language Implementation

CS4215 Programming Language Implementation CS4215 Programming Language Implementation You have 45 minutes to complete the exam. Use a B2 pencil to fill up the provided MCQ form. Leave Section A blank. Fill up Sections B and C. After finishing,

More information

Frequently asked questions from the previous class survey

Frequently asked questions from the previous class survey CS 370: OPERATING SYSTEMS [CPU SCHEDULING] Shrideep Pallickara Computer Science Colorado State University L15.1 Frequently asked questions from the previous class survey Could we record burst times in

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

CSC369 Lecture 5. Larry Zhang, October 19,2015

CSC369 Lecture 5. Larry Zhang, October 19,2015 CSC369 Lecture 5 Larry Zhang, October 19,2015 1 Describe your A1 experience using the feedback form 2 Announcements Assignment 2 out later this week, due November 11 Midterm next week in lecture: 9:10AM

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

Notes on the Exam. Question 1. Today. Comp 104:Operating Systems Concepts 11/05/2015. Revision Lectures (separate questions and answers)

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

Lecture #7: Implementing Mutual Exclusion

Lecture #7: Implementing Mutual Exclusion Lecture #7: Implementing Mutual Exclusion Review -- 1 min Solution #3 to too much milk works, but it is really unsatisfactory: 1) Really complicated even for this simple example, hard to convince yourself

More information

Producing Production Quality Software. Lecture 12: Concurrent and Distributed Programming Prof. Arthur P. Goldberg Fall, 2004

Producing Production Quality Software. Lecture 12: Concurrent and Distributed Programming Prof. Arthur P. Goldberg Fall, 2004 Producing Production Quality Software Lecture 12: Concurrent and Distributed Programming Prof. Arthur P. Goldberg Fall, 2004 Topics Models of concurrency Concurrency in Java 2 Why Use Concurrency? Enable

More information

Object Oriented Programming and Design in Java. Session 18 Instructor: Bert Huang

Object Oriented Programming and Design in Java. Session 18 Instructor: Bert Huang Object Oriented Programming and Design in Java Session 18 Instructor: Bert Huang Announcements Homework 4 due Mon. Apr. 19 No multithreading in programming part Final Exam Monday May 10, 9 AM - noon, 173

More information

Work Stealing. in Multiprogrammed Environments. Brice Dobry Dept. of Computer & Information Sciences University of Delaware

Work Stealing. in Multiprogrammed Environments. Brice Dobry Dept. of Computer & Information Sciences University of Delaware Work Stealing in Multiprogrammed Environments Brice Dobry Dept. of Computer & Information Sciences University of Delaware Outline Motivate the issue Describe work-stealing in general Explain the new algorithm

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

1995 Paper 10 Question 7

1995 Paper 10 Question 7 995 Paper 0 Question 7 Why are multiple buffers often used between producing and consuming processes? Describe the operation of a semaphore. What is the difference between a counting semaphore and a binary

More information

CPU Scheduling. The scheduling problem: When do we make decision? - Have K jobs ready to run - Have N 1 CPUs - Which jobs to assign to which CPU(s)

CPU Scheduling. The scheduling problem: When do we make decision? - Have K jobs ready to run - Have N 1 CPUs - Which jobs to assign to which CPU(s) 1/32 CPU Scheduling The scheduling problem: - Have K jobs ready to run - Have N 1 CPUs - Which jobs to assign to which CPU(s) When do we make decision? 2/32 CPU Scheduling Scheduling decisions may take

More information

Lecture 25: Board Notes: Threads and GPUs

Lecture 25: Board Notes: Threads and GPUs Lecture 25: Board Notes: Threads and GPUs Announcements: - Reminder: HW 7 due today - Reminder: Submit project idea via (plain text) email by 11/24 Recap: - Slide 4: Lecture 23: Introduction to Parallel

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

Introduction to OS Synchronization MOS 2.3

Introduction to OS Synchronization MOS 2.3 Introduction to OS Synchronization MOS 2.3 Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Mahmoud El-Gayyar / Introduction to OS 1 Challenge How can we help processes synchronize with each other? E.g., how

More information

Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore

Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Lecture - 20 Intermediate code generation Part-4 Run-time environments

More information

Comp 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) 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 information

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

Processes and Threads. Processes and Threads. Processes (2) Processes (1) Processes and Threads (Topic 2-1) 2 홍성수 Processes and Threads Question: What is a process and why is it useful? Why? With many things happening at once in a system, need some way of separating them all

More information

CPU Scheduling. The scheduling problem: When do we make decision? - Have K jobs ready to run - Have N 1 CPUs - Which jobs to assign to which CPU(s)

CPU Scheduling. The scheduling problem: When do we make decision? - Have K jobs ready to run - Have N 1 CPUs - Which jobs to assign to which CPU(s) CPU Scheduling The scheduling problem: - Have K jobs ready to run - Have N 1 CPUs - Which jobs to assign to which CPU(s) When do we make decision? 1 / 31 CPU Scheduling new admitted interrupt exit terminated

More information

Animation Part 2: MoveableShape interface & Multithreading

Animation Part 2: MoveableShape interface & Multithreading Animation Part 2: MoveableShape interface & Multithreading MoveableShape Interface In the previous example, an image was drawn, then redrawn in another location Since the actions described above can apply

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

CIS 1.5 Course Objectives. a. Understand the concept of a program (i.e., a computer following a series of instructions)

CIS 1.5 Course Objectives. a. Understand the concept of a program (i.e., a computer following a series of instructions) By the end of this course, students should CIS 1.5 Course Objectives a. Understand the concept of a program (i.e., a computer following a series of instructions) b. Understand the concept of a variable

More information

Don t write anything in the field marked Eventuell ekstra ID. For each subtask, choose the answer you think is the most correct one.

Don t write anything in the field marked Eventuell ekstra ID. For each subtask, choose the answer you think is the most correct one. Contact persons under the exam: Per Holager, tlf 99 61 78 36 Ole Edsberg tlf 95 28 15 86 Language: English EXAM IN COURSE TDT4165 PROGRAMMING LANGUAGES Saturday May 15th, 2004, 0900 1300 No printed or

More information

Last Class: Processes

Last Class: Processes Last Class: Processes A process is the unit of execution. Processes are represented as Process Control Blocks in the OS PCBs contain process state, scheduling and memory management information, etc A process

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

Lecture 5: Synchronization w/locks

Lecture 5: Synchronization w/locks Lecture 5: Synchronization w/locks CSE 120: Principles of Operating Systems Alex C. Snoeren Lab 1 Due 10/19 Threads Are Made to Share Global variables and static objects are shared Stored in the static

More information

Result: original lp in main is. Goal was.

Result: original lp in main is. Goal was. CSE 12, Week Two, Lecture Two Thursday s Discussion Section: Getting started on hw3 Goal: Call a method that assigns a variable (a long) to zero; that variable exists elsewhere: void func ( ) { ; main

More information

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009 CS211: Programming and Operating Systems Lecture 17: Threads and Scheduling Thursday, 05 Nov 2009 CS211 Lecture 17: Threads and Scheduling 1/22 Today 1 Introduction to threads Advantages of threads 2 User

More information