Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 91 Today’s class Mutual exclusion and synchronization 

Slides:



Advertisements
Similar presentations
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Advertisements

Operating Systems Part III: Process Management (Process Synchronization)
1 Chapter 5 Concurrency: Mutual Exclusion and Synchronization Principals of Concurrency Mutual Exclusion: Hardware Support Semaphores Readers/Writers Problem.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 6: Process Synchronization
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles Seventh Edition By William Stallings.
Concurrency: mutual exclusion and synchronization Slides are mainly taken from «Operating Systems: Internals and Design Principles”, 8/E William Stallings.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles Seventh Edition By William Stallings.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Enforcing Mutual Exclusion, Semaphores. Four different approaches Hardware support Disable interrupts Special instructions Software-defined approaches.
Enforcing Mutual Exclusion Message Passing. Peterson’s Algorithm for Processes P0 and P1 void P0() { while( true ) { flag[ 0 ] = false; /* remainder */
Concurrency: Mutual Exclusion and Synchronization Why we need Mutual Exclusion? Classical examples: Bank Transactions:Read Account (A); Compute A = A +
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
1 Semaphores Special variable called a semaphore is used for signaling If a process is waiting for a signal, it is suspended until that signal is sent.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
Concurrency: Mutual Exclusion and Synchronization
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
1 Chapter 5 Concurrency. 2 Concurrency 3 4 Mutual Exclusion: Hardware Support Test and Set Instruction boolean testset (int *i) { if (*i == 0) { *i.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Module 6: Process Synchronization.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Operating System 5 CONCURRENCY: MUTUAL EXCLUSION AND SYNCHRONIZATION.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings 1.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago.
Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago.
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.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
3 Chapter 5. Theme of OS Design? Management of processes and threads Multiprogramming Multiprocessing Distributed processing.
Chap 6 Synchronization. Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 4.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
1 Lecture 8: Concurrency: Mutual Exclusion and Synchronization(cont.) Advanced Operating System Fall 2009.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-5 Process Synchronization Department of Computer Science and Software.
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Operating System Chapter 5. Concurrency: Mutual Exclusion and Synchronization Lynn Choi School of Electrical Engineering.
Operating System Concepts and Techniques Lecture 13 Interprocess communication-2 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Interprocess Communication Race Conditions
Chapter 5 Concurrency: Mutual Exclusion and Synchronization
Chapter 5: Process Synchronization
Chapter 5 Concurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and Synchronization
Chapter 5: Process Synchronization
Concurrency: Mutual Exclusion and Synchronization
Critical section problem
Chapter 5 Concurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and Process Synchronization
Chapter 6: Process Synchronization
CSE 153 Design of Operating Systems Winter 19
Operating System 5 CONCURRENCY: MUTUAL EXCLUSION AND SYNCHRONIZATION
Synchronization CS Spring 2002.
Presentation transcript:

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 91 Today’s class Mutual exclusion and synchronization  Hardware support  Semaphores  Producer/Consumer problem  Readers/Writers problem

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 92 Mutual Exclusion: Hardware Support Interrupt Disabling  A process runs until it invokes an operating system service or until it is interrupted  Disabling interrupts guarantees mutual exclusion  Processor is limited in its ability to interleave programs  Multiprocessing - disabling interrupts on one processor will not guarantee mutual exclusion

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 93 Mutual Exclusion: Hardware Support while (true) { /* disable interrupts */ /* critical section */ /* enable interrupts */ /* remainder */ }

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 94 Mutual Exclusion: Hardware Support Special Machine Instructions  Performed in a single instruction cycle  Access to the memory location is blocked for any other instructions

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 95 Mutual Exclusion: Hardware Support Test and Set Instruction boolean testset (int i) { if (i == 0) { i = 1; return true; } else { return false; }

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 96 Mutual Exclusion Based on Test and Set

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 97 Mutual Exclusion: Hardware Support Exchange Instruction void exchange(int register, int memory) { int temp; temp = memory; memory = register; register = temp; }

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 98 Mutual Exclusion Based on Exchange

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 99 Mutual Exclusion Machine Instructions Advantages  Applicable to any number of processes on either a single processor or multiple processors sharing main memory  It is simple and therefore easy to verify  It can be used to support multiple critical sections

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 910 Mutual Exclusion Machine Instructions Disadvantages  Busy-waiting consumes processor time  Starvation is possible when a process leaves a critical section and more than one process is waiting.  Deadlock  If a low priority process has the critical region and a higher priority process needs it, the higher priority process will obtain the processor to wait for the critical region

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 911 Semaphores Special variable called a semaphore is used for signaling If a process is waiting for a signal, it is suspended until that signal is sent semSignal(s) transmits a signal via semaphore s semWait(s) receives a signal via semaphore s; if the signal has not yet been sent, the process is suspended until the transmission takes place

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 912 Semaphores Semaphore is a variable that has an integer value  May be initialized to a nonnegative number  semWait operation decrements the semaphore value; if it becomes negative then the process executing semWait is blocked, otherwise the process continues execution  semSignal operation increments the semaphore value; if the value is less than or equal to 0 then a process blocked by semWait is unblocked

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 913 Semaphore Primitives

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 914 Binary Semaphore Primitives

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 915 Mutual Exclusion Using Semaphores

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 916

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 917 Producer/Consumer Problem One or more producers are generating data and placing these in a buffer A single consumer is taking items out of the buffer one at time Only one producer or consumer may access the buffer at any one time

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 918 Producer producer: while (true) { /* produce item v */ b[in] = v; in++; }

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 919 Consumer consumer: while (true) { while (in <= out) /*do nothing */; w = b[out]; out++; /* consume item w */ }

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 920 Producer/Consumer Problem

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 921 Producer with Circular Buffer producer: while (true) { /* produce item v */ while ((in + 1) % n == out) /* do nothing */; b[in] = v; in = (in + 1) % n }

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 922 Consumer with Circular Buffer consumer: while (true) { while (in == out) /* do nothing */; w = b[out]; out = (out + 1) % n; /* consume item w */ }

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 923

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 924

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 925

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 926

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 927

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 928 Monitors Monitor is a software module Chief characteristics  Local data variables are accessible only by the monitor  Process enters monitor by invoking one of its procedures  Only one process may be executing in the monitor at a time

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 929

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 930

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 931

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 932 Message Passing Enforce mutual exclusion Exchange information send (destination, message) receive (source, message)

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 933 Synchronization Message communication requires some level of synchronization – a message cannot be received before it is sent Sender and receiver may or may not be blocking (waiting for message) Blocking send, blocking receive  Both sender and receiver are blocked until message is delivered  Called a rendezvous

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 934 Synchronization Nonblocking send, blocking receive  Sender continues on  Receiver is blocked until the requested message arrives Nonblocking send, nonblocking receive  Neither party is required to wait

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 935 Addressing Direct addressing  Send primitive includes a specific identifier of the destination process  Receive primitive could know ahead of time which process a message is expected  Receive primitive could use source parameter to return a value when the receive operation has been performed

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 936 Addressing Indirect addressing  Messages are sent to a shared data structure consisting of queues  Queues are called mailboxes  One process sends a message to the mailbox and the other process picks up the message from the mailbox

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 937 Message Format

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 938 Readers/Writers Problem Any number of readers may simultaneously read the file Only one writer at a time may write to the file If a writer is writing to the file, no reader may read it

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 939

Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 940