Threading And Parallel Programming Constructs

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
Operating Systems: Monitors 1 Monitors (C.A.R. Hoare) higher level construct than semaphores a package of grouped procedures, variables and data i.e. object.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Chapter 6 Process Synchronization Bernard Chen Spring 2007.
Chapter 6: Process Synchronization
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
8a-1 Programming with Shared Memory Threads Accessing shared data Critical sections ITCS4145/5145, Parallel Programming B. Wilkinson Jan 4, 2013 slides8a.ppt.
1 Semaphores and Monitors: High-level Synchronization Constructs.
Distributed Operating Systems CS551 Colorado State University at Lockheed-Martin Lecture 5 -- Spring 2001.
1 CS318 Project #3 Preemptive Kernel. 2 Continuing from Project 2 Project 2 involved: Context Switch Stack Manipulation Saving State Moving between threads,
Concurrent Processes Lecture 5. Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Synchronization (Or The “Joys” of Concurrent.
CS444/CS544 Operating Systems Synchronization 2/21/2007 Prof. Searleman
Monitors CSCI 444/544 Operating Systems Fall 2008.
Semaphores CSCI 444/544 Operating Systems Fall 2008.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Adopted from and based on Textbook: Operating System Concepts – 8th Edition, by Silberschatz, Galvin and Gagne Updated and Modified by Dr. Abdullah Basuhail,
Semaphores Questions answered in this lecture: Why are semaphores necessary? How are semaphores used for mutual exclusion? How are semaphores used for.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
CS510 Concurrent Systems Introduction to Concurrency.
Semaphores and Bounded Buffer Andy Wang Operating Systems COP 4610 / CGS 5765.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
6.3 Peterson’s Solution The two processes share two variables: Int turn; Boolean flag[2] The variable turn indicates whose turn it is to enter the critical.
CSCI-455/552 Introduction to High Performance Computing Lecture 19.
Lecture 8 Page 1 CS 111 Online Other Important Synchronization Primitives Semaphores Mutexes Monitors.
Chapter 7 -1 CHAPTER 7 PROCESS SYNCHRONIZATION CGS Operating System Concepts UCF, Spring 2004.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
C H A P T E R E L E V E N Concurrent Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Operating Systems COMP 4850/CISG 5550 Interprocess Communication, Part II Dr. James Money.
Synchronization CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
CS 153 Design of Operating Systems Winter 2016 Lecture 7: Synchronization.
Process Synchronization. Objectives To introduce the critical-section problem, whose solutions can be used to ensure the consistency of shared data To.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Process Synchronization. Concurrency Definition: Two or more processes execute concurrently when they execute different activities on different devices.
Interprocess Communication Race Conditions
CS703 – Advanced Operating Systems
COT 4600 Operating Systems Fall 2009
Process Synchronization
Background on the need for Synchronization
Process Synchronization
Outline Other synchronization primitives
Other Important Synchronization Primitives
Semaphores and Condition Variables
Chapter 5: Process Synchronization
Programming with Shared Memory
Midterm review: closed book multiple choice chapters 1 to 9
Shared Memory Programming
Lecture 2 Part 2 Process Synchronization
Concurrency: Mutual Exclusion and Process Synchronization
Chapter 6 Synchronization Principles
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization
CSE 153 Design of Operating Systems Winter 19
CSE 153 Design of Operating Systems Winter 2019
CS333 Intro to Operating Systems
Chapter 6: Synchronization Tools
Programming with Shared Memory - 2 Issues with sharing data
Monitors and Inter-Process Communication
CSE 542: Operating Systems
CSE 542: Operating Systems
Presentation transcript:

Threading And Parallel Programming Constructs Module III

Introduction Basic parallel programming constructs Topics : Synchronization & primitives used Critical Section Deadlock Use of messages Concepts based on flow control

Synchronization Mechanism to impose constraints on the order of execution Resolves conflict between threads Coordinate thread execution and manage shared data For example : a message must be sent before it is received Semaphore, Monitor, Mutex, Locks, Critical Sections

2 types of synchronization Mutual Exclusion : One thread blocks a critical section – and one or more threads wait for their turns Controlled by scheduler Condition Synchronization : A thread is blocked until the system state achieves some particular condition

Synchronization function Proper synchronizations ensures proper order of execution and proper result

Operational Flow of Threads for an application How Synchronization is performed in an actual multi-threaded implementation Operational Flow of Threads for an application

Synchronization Primitives Semaphore Lock Condition Variable Usage of fence (also called barrier)

1. Semaphores Software oriented primitive Introduced by Dijkstra Semaphore is a single integer, sem, that apart from initialisation is accessed only through 2 operations Wait() : originally termed P (proberen, means “to test”) Signal() : originally termed V (verhogen, “to increment”)

P denotes potential delay or wait V denotes release of thread Semaphore value sem must have exclusive access from the threads P operation blocks a thread. V allows the thread to continue execution

2 types of semaphores based on values it can take Binary : Also called mutex locks Values restricted between 0 and 1 Counting : Used to control access to a given resource Semaphore indicates number of resource. When a thread wants to use a resource, wait() : decrement When a thread releases reource, signal() : increment

2 types of semaphores from user perspective Strong All threads that call for P are satisfied Weak No guarantee of service to threads. Threads might starve

Mutual exclusion of parallel threads using P and V

Disadvantage of semaphores Busy waiting Any other process wanting to access the critical section should execute entry code continuously

Case Study using PC Problem= bounded buffer

2. Locks Acquire() : Waits for lock state to be unlocked and sets the lock state to lock. Release() : Automatically changes the lock state from locked to unlocked. Only one thread can hold a lock at a time. Acquire – operation on shared data – release

Locks must not be held for long periods of time Explicit locks and implicit locks : safe and reliable to use explicit locks

Lock Types Mutex Recursive Locks Read-Write Locks Spin Locks

Mutex Simplest lock Acquire and release Release : Does not depend on release() only Timer attribute Exception

Recursive Locks Locks being acquired by the thread holding the lock itself No deadlock Each thread has to release it for each time it acquired the lock Slower performance

Read Write Locks Also called multiple read-single write locks Allows multiple threads read access to a shared resource, but limits write access to a single thread

Spin Locks Waiting threads must “spin”, not get blocked. Poll the state of critical section lock

3. Condition Variables (c) no stored value to test Using a lock L, 3 basic atomic operations are performed on C Wait(L) : releases lock and waits Signal(L) : enables one of the waiting threads to run Broadcast(L) : enables all of the waiting threads to run An assosciation between condition variable C and lock L

Critical Section A portion of code where shared dependency variables reside. No two processes should execute in their critical sections at the same time. Entry section, exit section, remainder section

Also called Synchronization blocks Minimize size of synchronization block Larger CS are split to multiple code blocks

Deadlocks Occur when a thread is waiting for a resource of another thread that will never become available. Example : Cricket Types of deadlock : Self deadlock Recursive deadlock Lock ordering deadlock

1. Self deadlock A thread requests for a lock already held by itself.

Recursive deadlock Lock ordering Wake up path of one thread lies on another thread Lock ordering

Deadlock transition diagram Threads can transition from one state to another by requesting, acquiring or freeing a resource

Messages Method of communication to transfer information Intra process, inter process, process-process Shared memory vs msg passing model MPI : message passing interface

Flow control based concepts Fence & barrier

Implementation dependant threading features Syntax of threadsis different b/w environments Critical section synchronisation