Global Environment Model

Similar documents
Concept of a process

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

Concurrency: a crash course

Synchronization Principles I

C09: Process Synchronization

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

7: Interprocess Communication

Programming in Parallel COMP755

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

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

Semaphores. May 10, Mutual exclusion with shared variables is difficult (e.g. Dekker s solution).

OS Process Synchronization!

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

IV. Process Synchronisation

Dealing with Issues for Interprocess Communication

CSC 1600: Chapter 6. Synchronizing Threads. Semaphores " Review: Multi-Threaded Processes"

COP 4225 Advanced Unix Programming. Synchronization. Chi Zhang

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

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

IT 540 Operating Systems ECE519 Advanced Operating Systems

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

Parallel Programming Languages COMP360

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

Synchronization for Concurrent Tasks

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

Dept. of CSE, York Univ. 1

OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S. TANENBAUM ALBERT S. WOODHULL. Chap. 2.2 Interprocess Communication

Chapter 6: Process Synchronization

PROCESS SYNCHRONIZATION

Chapter 6: Process Synchronization

Concurrent Processes Rab Nawaz Jadoon

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

Chapter 7: Process Synchronization!

Lecture 6. Process Synchronization

Synchronization: Basics

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

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

CS 153 Design of Operating Systems Winter 2016

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

Achieving Synchronization or How to Build a Semaphore

CS420: Operating Systems. Process Synchronization

Symmetric Multiprocessors: Synchronization and Sequential Consistency

Parallel Computer Architecture Spring Distributed Shared Memory Architectures & Directory-Based Memory Coherence

CS3733: Operating Systems

CHAPTER 6: PROCESS SYNCHRONIZATION

Introduction to OS Synchronization MOS 2.3

Process Management And Synchronization

Process Synchronization

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Part II Process Management Chapter 6: Process Synchronization

CS370 Operating Systems

Interprocess Communication and Synchronization

Process Synchronization

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Synchronization: Basics

Outline Part 2. Semaphores. Semaphore Usage. Objectives: Administrative details:

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

MS Windows Concurrency Mechanisms Prepared By SUFIAN MUSSQAA AL-MAJMAIE

Synchronization: Advanced

Synchronization. CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han

Critical Section Problem: Example

CS 550 Operating Systems Spring Concurrency Semaphores, Condition Variables, Producer Consumer Problem

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

Synchronization I. Jo, Heeseung

Process Synchronization

Process Synchronization

Explain briefly how starvation may occur in process scheduling. (2 marks)

Mutual Exclusion and Synchronization

Semaphores. To avoid busy waiting: when a process has to wait, it will be put in a blocked queue of processes waiting for the same event

Semaphores. Semaphores. Semaphore s operations. Semaphores: observations

Chapter 7: Process Synchronization. Background

Chapters 5 and 6 Concurrency

Process Coordination

Roadmap. Shared Variables: count=0, buffer[] Producer: Background. Consumer: while (1) { Race Condition. Race Condition.

Midterm 1, CSE 451, Winter 2001 (Prof. Steve Gribble)

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

Process Synchronisation (contd.) Operating Systems. Autumn CS4023

Running. Time out. Event wait. Schedule. Ready. Blocked. Event occurs

Section I Section Real Time Systems. Processes. 1.4 Inter-Processes Communication (part 1)

Process Synchronization

CSCI 8530 Advanced Operating Systems. Part 5 Process Coordination and Synchronization

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

Chapter 8. Basic Synchronization Principles

Introduction to Operating Systems

EECE.4810/EECE.5730: Operating Systems Spring 2017 Homework 2 Solution

Synchronization: semaphores and some more stuff. Operating Systems, Spring 2018, I. Dinur, D. Hendler and R. Iakobashvili

Announcements. ECE4750/CS4420 Computer Architecture L17: Memory Model. Edward Suh Computer Systems Laboratory

Last class: Today: CPU Scheduling. Start synchronization

Midterm on next week Tuesday May 4. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 9

Chapter 7: Process Synchronization. Background. Illustration

Principles of Operating Systems CS 446/646

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

Concurrency. Chapter 5

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

CS 152 Computer Architecture and Engineering. Lecture 19: Synchronization and Sequential Consistency

Process Synchronization - I

Synchronization. CSE 2431: Introduction to Operating Systems Reading: Chapter 5, [OSC] (except Section 5.10)

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Recap: Thread. What is it? What does it need (thread private)? What for? How to implement? Independent flow of control. Stack

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

Transcription:

Global Environment Model MUTUAL EXCLUSION PROBLEM The operations used by processes to access to common resources (critical sections) must be mutually exclusive in time No assumptions should be made about relative process speed A, B critical sections A B Example During their execution P1 and P2 access a common variable count(i.v.=o) and increment it by 1 t 1

Example When P1 and P2 terminate their executions count must be incremented by 2 count=2 Note that the increment of count, when P1 execute it, may be implemented in machine language as: reg1 = count reg1 = reg1 +1 count = reg1 Where reg1 is a local CPU register used by P1 Similarly the increment of count, when P2 executes it, may be implemented in machine language as: reg2 = count reg2 = reg2 +1 count = reg2 where reg2 is a local CPU register used by P2 The concurrent execution of the statement ++count is equivalent to a sequential execution where the statements can be interleaved in any arbitrary order 2

TO: reg1=count (reg1=o) (P1) T1: reg2=count (reg2=o) (P2) T2: reg2=reg2+1 (reg2=1) (P2) T3: count=reg2 (count=1) (P2) T4: reg1=reg1+1 (reg1=1) (P1) T5: count=reg1 (count=1) (P1) RACE CONDITION: Several processes concurrently access and manipulate the same data RACE CONDITION: The outcome of the execution depends on the particular order in wich the access takes place To prevent race conditions, we need to assure that only one process at a time can be operating on the same variable count 3

P 1 while (busy ==1); To grant that invariant, we need some form of process synchronization SOLUTION TO THE MUTUAL EXCLUSION PROBLEM busy = 1 the resource is busy busy = O the resource is free busy =1 < critical section A>; busy =O; P 2 while (busy ==1); busy =1 < critical section B>; busy =O; T O : P 1 executes while and busy=o T 1 : P 2 executes while and busy=o T 2 : P 1 set busy=1 and accesses to A T 3 : P 2 set busy=1 and accesses to B Both processes have simultaneous access to their critical section 4

TSL (Test and Set Lock) Instruction that reads and modifies the contents of a memory word in an indivisible way The CPU, while executing the TSL instruction, locks the memory bus to prohibit other CPUs from accessing memory until the instruction is completed TSL R, x: It reads the content of x into the register R and then stores a non zero value at that memory address TSL R, x: The operations of reading a word and storing into it are garantee to be indivisible by the hardware level 5

lock(x), unlock(x): lock(x): unlock(x): TSL register, x CMP register,o JNE lock RET (copy x to register and set x=1) (was x zero?) (if non zero the cycle is restarted) (return to caller; critical region entered) MOVE x, O RET (store a O in x) (return to caller) Soluzione con lock(x) e unlock(x): Soluzione con lock(x) e unlock(x): P 1 lock(x); <sezione critica A>; unlock (x); P 2 lock(x); <sezione critica B>; unlock (x) ; 6

SOLUTION PROPERTIES busy waiting multiprocessor systems very shorts critical sections x R P 1 P 2 PR 1 PR n SEMAPHORES A semaphor s is a integer non negative variable, initialized to a nonnegative value s.value s is associated with a waiting list, in wich are linked the PCBs of processes blocked on s. s.queue s 7

A semaphore s is accessed only via two standard operations P (s) V (s) P(s) If s.value>o the process continues its execution, if s.value=o the process is blocked in the s.queue V(s) A process in the s.queue is waked and extracted; its state is modified from blocked to ready void P(s) { } if (s.value==o) <the process is blocked and its PCB is inserted in the s.queue>; else s.value= s.value-1; 8

void V(s) { } if ( < there is at least one process in s.queue>) <the PCB of the first of these processes is taken out from s.queue and its state is modified from blocked to ready>; else s.value = s.value + 1; As a consequence of the execution of a V(s) the state of the process does not change The decision of wich process is to be extracted from the s.queue is taken with a FIFO policy MUTUAL EXCLUSION mutex: semaphore associated to the shared resource (i. v. mutex=1) P (mutex) <sezione critica> V (mutex) 9

P1 P(mutex) <A> V (mutex) P3 P (mutex) <C> V (mutex) P2 P(mutex) <B> V (mutex) P and V must be indivisible operations The modification of the value of the semaphore and the possible blocking or waking up of a process must be indivisible operations P,V: critical sections with reference to the data structure represented by mutex (mutex.value, mutex.queue) INDIVISIBILITY OF P AND V BY Disabling interrupts (when P,V are executing on the same processor) 10

INDIVISIBILITY OF P AND V BY Using lock(x), unlock(x)( when P,V are executing on different processors) indivisible P,V lock(x); P (mutex); unlock(x); <sezione critica>; lock(x); V (mutex); unlock(x); x mutex R P 1 P 2 PR 1 PR n 11