Concurrency: a crash course

Similar documents
Synchronization for Concurrent Tasks

Chapter 6: Process Synchronization

Dealing with Issues for Interprocess Communication

Lecture 8: September 30

The University of Texas at Arlington

IT 540 Operating Systems ECE519 Advanced Operating Systems

IV. Process Synchronisation

CS420: Operating Systems. Process Synchronization

The University of Texas at Arlington

Introduction to Real-Time Operating Systems

HY 345 Operating Systems

High-level Synchronization

HY345 - Operating Systems

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

CS 333 Introduction to Operating Systems. Class 4 Concurrent Programming and Synchronization Primitives

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 8: Semaphores, Monitors, & Condition Variables

CIS Operating Systems Application of Semaphores. Professor Qiang Zeng Spring 2018

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem?

PROCESS SYNCHRONIZATION

Models of concurrency & synchronization algorithms

Monitors; Software Transactional Memory

G52CON: Concepts of Concurrency

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

MS Windows Concurrency Mechanisms Prepared By SUFIAN MUSSQAA AL-MAJMAIE

Concurrency. Chapter 5

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

Last Class: Synchronization. Review. Semaphores. Today: Semaphores. MLFQ CPU scheduler. What is test & set?

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Last Class: Synchronization

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

Global Environment Model

Interprocess Communication and Synchronization

Chapter 5 Asynchronous Concurrent Execution

Monitors; Software Transactional Memory

C09: Process Synchronization

Operating Systems. Operating Systems Summer 2017 Sina Meraji U of T

Process/Thread Synchronization

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

Deadlock and Monitors. CS439: Principles of Computer Systems September 24, 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

Processes and Threads. Industrial Programming. Processes and Threads (cont'd) Processes and Threads (cont'd)

Concept of a process

Process Synchronisation (contd.) Operating Systems. Autumn CS4023

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

Synchronization. CS 416: Operating Systems Design, Spring 2011 Department of Computer Science Rutgers University

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

Multi-core Architecture and Programming

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

CS533 Concepts of Operating Systems. Jonathan Walpole

Concurrent Programming. CS105 Programming Languages Supplement

Process Synchronization

Note: in this document we use process and thread interchangeably.

Java Monitors. Parallel and Distributed Computing. Department of Computer Science and Engineering (DEI) Instituto Superior Técnico.

Condition Variables CS 241. Prof. Brighten Godfrey. March 16, University of Illinois

Page 1. Goals for Today" Atomic Read-Modify-Write instructions" Examples of Read-Modify-Write "

Synchronization Spinlocks - Semaphores

Synchronization. Coherency protocols guarantee that a reading processor (thread) sees the most current update to shared data.

Concurrency: Deadlock and Starvation

Chapter 5 Concurrency: Mutual Exclusion and Synchronization

Discussion CSE 224. Week 4

Systems Programming & Scripting

2.c Concurrency Mutual exclusion & synchronization mutexes. Unbounded buffer, 1 producer, N consumers

CSC501 Operating Systems Principles. Process Synchronization

Learning Outcomes. Concurrency and Synchronisation. Textbook. Concurrency Example. Inter- Thread and Process Communication. Sections & 2.

Writing Parallel Programs COMP360

Chair of Software Engineering. Java and C# in depth. Carlo A. Furia, Marco Piccioni, Bertrand Meyer. Java: concurrency

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

CS3502 OPERATING SYSTEMS

Deadlock and Monitors. CS439: Principles of Computer Systems February 7, 2018

Week 3. Locks & Semaphores

Concurrency and Synchronisation

Synchronization. Before We Begin. Synchronization. Example of a Race Condition. CSE 120: Principles of Operating Systems. Lecture 4.

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

Concurrency. Glossary

Threads Questions Important Questions

ECE 462 Object-Oriented Programming using C++ and Java. Scheduling and Critical Section

Programming Languages

Reminder from last time

Operating Systems ECE344

EE458 - Embedded Systems Lecture 8 Semaphores

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

Process Synchronization

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

Chapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition

CSE 120: Principles of Operating Systems. Lecture 4. Synchronization. October 7, Prof. Joe Pasquale

COP 4225 Advanced Unix Programming. Synchronization. Chi Zhang

MULTITHREADING AND SYNCHRONIZATION. CS124 Operating Systems Fall , Lecture 10

Threads. Threads The Thread Model (1) CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5

Synchronization Principles I

Concurrent Processes Rab Nawaz Jadoon

CS370 Operating Systems

Synchronization problems with semaphores

Process Synchronization

Semaphores and Monitors: High-level Synchronization Constructs

Chapter 6: Process Synchronization

Page 1. Goals for Today" Atomic Read-Modify-Write instructions" Examples of Read-Modify-Write "

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

Interprocess Communication By: Kaushik Vaghani

Processes & Concurrency

Processes & Concurrency

Transcription:

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 in parallel logical vs. physical parallelism parallel vs. distributed What s concurrency good for? improved user experience applications carry out several tasks at once better usage of resources interactive computing performance clusters and multi-core CPUs 2

Processes and threads Concurrency can have two levels of granularity, according to what is the unit of parallel computation Processes the abstraction of a running program includes program counter, registers, variables,... different processes have independent address spaces Threads an independent thread of execution within a process a lightweight process threads within the same process share the address space This brief introduction refers to threads, but the same notions apply to processes as well 3

Coordination of threads Threads need to coordinate when accessing the shared memory to avoid race conditions inconsistent access to shared resources -- shared memory s: shared INTEGER invariant s 0 end -- thread A -- thread B if s > 0 then s := 0 s := s 1 end 4

Coordination of threads Coordination must guarantee mutual exclusion when accessing shared resources a section of code that accesses some shared resource is called critical region at any given time, no more than one thread should be in the critical region -- A s crit. reg. -- B s crit. reg. if s > 0 then s := 0 s := s 1 end 5

Coordination mechanisms for shared memory A few coordination mechanisms, roughly in increasing level of abstraction We won t specifically discuss how to use synchronization mechanisms to avoid problems such as deadlocks, starvation, livelocks, etc. Locks a lock is a variable (or an object) that is owned by no more than one thread at a time locks can be acquired and released guarding with locks the access to critical regions is a way to ensure mutual exclusion 6

Coordination mechanisms for shared memory Mutexes a way to implement locks a mutex is a binary variable accessed with primitives lock and unlock lock: if the mutex is unlocked acquire the lock, otherwise suspend execution unlock : release the lock and resume all suspended executions the lock and unlock operations are guaranteed to be non-interruptible 7

Mutex: example -- shared memory s: shared INTEGER invariant s 0 end -- mutex m: MUTEX -- thread A -- thread B m.lock m.lock if s > 0 then s := 0 s := s 1 m.unlock end m.unlock 8

Coordination mechanisms for shared memory Semaphores generalization of mutexes an integer variable that can be atomically incremented (up) and decremented, if its value is positive (down) invented by Dijkstra (1965) 9

Coordination mechanisms for shared memory Monitors a collection of routines (methods) that are guaranteed mutually exclusive access to shared resources no more than one routine in the monitor is active at once in other words: only one thread can be active in a monitor at any instant threads within the same monitor coordinate with signals a thread may not be able to proceed because it needs some other thread s work. Then it can wait and yield control to other threads. when a thread performs an action that some other threads may be waiting for it can signal it and wake them up (interrupting their waiting) invented by Brinch Hansen (1973) and Hoare (1974) 10

Monitors: example mon is monitor s: INTEGER invariant s 0 end decrement do if s > 0 then s := s 1 end end set_zero do s := 0 end end -- monitor 11