Global Environment Model

Slides:



Advertisements
Similar presentations
1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
Advertisements

Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Operating Systems Part III: Process Management (Process Synchronization)
Global Environment Model. MUTUAL EXCLUSION PROBLEM The operations used by processes to access to common resources (critical sections) must be mutually.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Chapter 2 Processes and Threads
Chapter 6: Process Synchronization
Background Concurrent access to shared data can lead to inconsistencies Maintaining data consistency among cooperating processes is critical What is wrong.
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.
EEE 435 Principles of Operating Systems Interprocess Communication Pt II (Modern Operating Systems 2.3)
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
Interprocess Communication
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Concurrency in Shared Memory Systems Synchronization and Mutual Exclusion.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Semaphores. Announcements No CS 415 Section this Friday Tom Roeder will hold office hours Homework 2 is due today.
Synchronization Principles. Race Conditions Race Conditions: An Example spooler directory out in 4 7 somefile.txt list.c scores.txt Process.
1 CS 333 Introduction to Operating Systems Class 4 – Synchronization Primitives Semaphores Jonathan Walpole Computer Science Portland State University.
Chapter 2.3 : Interprocess Communication
1 Chapter 6: Concurrency: Mutual Exclusion and Synchronization Operating System Spring 2007 Chapter 6 of textbook.
Jonathan Walpole Computer Science Portland State University
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
1 Outline Processes Threads Inter-process communication (IPC) Classical IPC problems Scheduling.
1 Interprocess Communication Race Conditions Two processes want to access shared memory at same time.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
1 Race Conditions/Mutual Exclusion Segment of code of a process where a shared resource is accessed (changing global variables, writing files etc) is called.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Introduction to Concurrency.
Process Synchronization Continued 7.2 Critical-Section Problem 7.3 Synchronization Hardware 7.4 Semaphores.
1 Concurrency: Mutual Exclusion and Synchronization Module 2.2.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Chapter 7 -1 CHAPTER 7 PROCESS SYNCHRONIZATION CGS Operating System Concepts UCF, Spring 2004.
Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Synchronization CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
1 Processes and Threads Part II Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Operating System Concepts and Techniques Lecture 13 Interprocess communication-2 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and.
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.
CE Operating Systems Lecture 8 Process Scheduling continued and an introduction to process synchronisation.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
Process Synchronization. Concurrency Definition: Two or more processes execute concurrently when they execute different activities on different devices.
CS703 – Advanced Operating Systems
Process Synchronization: Semaphores
Background on the need for Synchronization
G.Anuradha Reference: William Stallings
Chapter 5: Process Synchronization
Lecture 12: Peterson’s Solution and Hardware Support
Lecture 13: Producer-Consumer and Semaphores
Lecture 11: Mutual Exclusion
Concurrency: Mutual Exclusion and Synchronization
Jonathan Walpole Computer Science Portland State University
Lecture 22 Syed Mansoor Sarwar
Process Synchronization
Jonathan Walpole Computer Science Portland State University
Grades.
Concurrency: Mutual Exclusion and Process Synchronization
Chapter 6: Process Synchronization
Kernel Synchronization II
Lecture 12: Peterson’s Solution and Hardware Support
Lecture 13: Producer-Consumer and Semaphores
CS333 Intro to Operating Systems
Synchronization.
Chapter 6: Synchronization Tools
Presentation transcript:

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 t

Example During their execution P1 and P2 access a common variable count(i.v.=O) and increment it by 1

Example When P1 and P2 terminate their executions count must be incremented by 2 count=2

Where reg1 is a local CPU register used by P1 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

where reg2 is a local CPU register used by P2 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

TO:. reg1=count. (reg1=O) (P1) T1:. reg2=count. (reg2=O) (P2). T2: 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

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 P1 while (busy ==1); busy =1 < critical section A>; busy =O;

< critical section B>; busy =O; P2 while (busy ==1); busy =1 < critical section B>; busy =O;

Both processes have simultaneous access to their critical section TO: P1 executes while and busy=O T1: P2 executes while and busy=O T2: P1 set busy=1 and accesses to A T3: P2 set busy=1 and accesses to B Both processes have simultaneous access to their critical section

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

lock(x) , unlock(x): lock(x): TSL register, x (copy x to register and set x=1) CMP register,O (was x zero?) JNE lock (if non zero the cycle is restarted) RET (return to caller; critical region entered)

unlock(x): MOVE x, O (store a O in x) RET (return to caller)

Soluzione con lock(x) e unlock(x): P1 lock(x); <sezione critica A>; unlock (x);

Soluzione con lock(x) e unlock(x): P2 lock(x); <sezione critica B>; unlock (x) ;

SOLUTION PROPERTIES busy waiting multiprocessor systems “very shorts” critical sections

x R P1 P2 PR1 PRn

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

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 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; }

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

P1 P2 P(mutex) P(mutex) <A> <B> V (mutex) V (mutex) P3 P (mutex) <C> 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)

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>; V (mutex);

x R P1 P2 PR1 PRn mutex