Sarah Diesburg Operating Systems COP 4610

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.
Synchronization NOTE to instructors: it is helpful to walk through an example such as readers/writers locks for illustrating the use of condition variables.
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.
PROCESS SYNCHRONIZATION READINGS: CHAPTER 5. ISSUES IN COOPERING PROCESSES AND THREADS – DATA SHARING Shared Memory Two or more processes share a part.
Ch 7 B.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
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.
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
1 CS318 Project #3 Preemptive Kernel. 2 Continuing from Project 2 Project 2 involved: Context Switch Stack Manipulation Saving State Moving between threads,
More Synchronization, Semaphores Vivek Pai / Kai Li Princeton University.
6/16/2015 Chapter Eight Process Synchronisation. Index Objectives Concurrent processes and Asynchronous concurrent processes Process synchronisation Mutual.
Semaphores. Announcements No CS 415 Section this Friday Tom Roeder will hold office hours Homework 2 is due today.
CS470 Lab 4 TA Notes. Objective Simulate the activities of a producer and consumer – Page 326 Use thread synchronization to solve the producer-consumer.
Semaphores, mutexes and condition variables. semaphores Two types – Binary – 0 or 1 – Counting 0 to n Wait – decrements > 0 forces a wait Post or signal.
Chapter 2.3 : Interprocess Communication
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Synchronization Andy Wang Operating Systems COP 4610 / CGS 5765.
9/8/2015cse synchronization-p1 © Perkins DW Johnson and University of Washington1 Synchronization Part 1 CSE 410, Spring 2008 Computer Systems.
Pthread (continue) General pthread program structure –Encapsulate parallel parts (can be almost the whole program) in functions. –Use function arguments.
Homework 3-4 Sarah Diesburg Operating Systems COP 4610.
Semaphores and Bounded Buffer Andy Wang Operating Systems COP 4610 / CGS 5765.
SYNCHRONIZATION Module-4. scheduling Scheduling is an operating system mechanism that arbitrate CPU resources between running tasks. Different scheduling.
Implementing Synchronization. Synchronization 101 Synchronization constrains the set of possible interleavings: Threads “agree” to stay out of each other’s.
Semaphores and Bounded Buffer. Semaphores  Semaphore is a type of generalized lock –Defined by Dijkstra in the last 60s –Main synchronization primitives.
COMP 111 Threads and concurrency Sept 28, Tufts University Computer Science2 Who is this guy? I am not Prof. Couch Obvious? Sam Guyer New assistant.
1 Synchronization Threads communicate to ensure consistency If not: race condition (non-deterministic result) Accomplished by synchronization operations.
Problems with Semaphores Used for 2 independent purposes –Mutual exclusion –Condition synchronization Hard to get right –Small mistake easily leads to.
Practice Chapter Five.
Operating Systems COMP 4850/CISG 5550 Interprocess Communication, Part II Dr. James Money.
CS4315A. Berrached:CMS:UHD1 Process Synchronization Chapter 8.
1 Processes and Threads Part II Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Implementing Lock. From the Previous Lecture  The “too much milk” example shows that writing concurrent programs directly with load and store instructions.
3/17/2016cse synchronization-p2 © Perkins, DW Johnson and University of Washington1 Synchronization Part 2 CSE 410, Spring 2008 Computer.
Implementing Mutual Exclusion Andy Wang Operating Systems COP 4610 / CGS 5765.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Mutual Exclusion Mutexes, Semaphores.
CS162 Section 2. True/False A thread needs to own a semaphore, meaning the thread has called semaphore.P(), before it can call semaphore.V() False: Any.
Operating Systems NWEN 301 Lecture 6 More Concurrency.
Homework 3-4 Sarah Diesburg Operating Systems COP 4610.
Synchronization Exercises. Exercise 1 r Let S be a semaphore that is initialized to 2 r Consider the following: down(S) up(S) down(S) r Does this program.
CS703 - Advanced Operating Systems
Outline Introduction Centralized shared-memory architectures (Sec. 5.2) Distributed shared-memory and directory-based coherence (Sec. 5.4) Synchronization:
Scheduling Review FIFO: RR: + simple
Sarah Diesburg Operating Systems COP 4610
CS703 – Advanced Operating Systems
Background on the need for Synchronization
Interprocess Communication (3)
1 July 2015 Charles Reiss CS162: Operating Systems and Systems Programming Lecture 7: Synchronization: Lock Implementation,
Monitors, Condition Variables, and Readers-Writers
Introduction to Operating Systems
Lecture 13: Producer-Consumer and Semaphores
CSCI 511 Operating Systems Chapter 5 (Part B) Mutual Exclusion, Semaphores Dr. Frank Li.
The Critical-Section Problem (Two-Process Solution)
Andy Wang Operating Systems COP 4610 / CGS 5765
Semaphores and Bounded Buffer
Lecture 22 Syed Mansoor Sarwar
CS703 - Advanced Operating Systems
Global Environment Model
Implementing Mutual Exclusion
Implementing Mutual Exclusion
September 12, 2012 Ion Stoica CS162 Operating Systems and Systems Programming Lecture 5 Semaphores, Conditional Variables.
Lecture 13: Producer-Consumer and Semaphores
CSE 451: Operating Systems Winter Module 7 Semaphores and Monitors
CS333 Intro to Operating Systems
Don Porter Portions courtesy Emmett Witchel
Review The Critical Section problem Peterson’s Algorithm
Sarah Diesburg Operating Systems CS 3430
Presentation transcript:

Sarah Diesburg Operating Systems COP 4610 Homework 3-4 Sarah Diesburg Operating Systems COP 4610

1. All Possible Execution Orders Thread A Thread B x = 3; y = 2; x = y - 1; y = x + 1; (x = ?, y = ?) x = 3 y = 2 (x = ?, y = 2) (x = 3, y = ?) x = y - 1 y = 2 x = 3 y = x + 1 (x = 3, y = 2) (x = ?, y = ?) (x = ?, y = ?) y = 2 y = x + 1 x = y - 1 y = x + 1 x = 3 x = y - 1 (x = ?, y = 2) (x = 1, y = 2) (x = 3, y = 4) (x = 3, y = ?) (x = ?, y = ?) (x = 1, y = 2) (x = 3, y = 4) (x = ?, y = ?)

2. Why does disabling interrupts not work on multi-processors? Interrupts are disabled on a per-CPU basis A thread running on another CPU could enter the critical area

3. Too Much Milk w/ Busy Waits //define the busy-wait locks value = 0; Lock::Acquire() { // while the previous value is BUSY, loop while (test_and_set(value) == 1); } Lock::Release() {

3. (cont.) //Dumb Lock::Acquire(value) if(no milk) { //go get milk Lock::Release(value) //Dumber Lock::Acquire(value) if(no milk) { //go get milk Lock::Release(value)

4. Does this work? // consumer waits on 0 semaphore nLoadedBuffers = 0; // producer waits on 0 semaphore nFreeBuffers = N; // N >= 2 // one thread waits when another thread is // modifying the buffer semaphore mutex = 1; Producer() { 1. P(nFreeBuffers); 2. P(mutex); 3. // put 1 item in the buffer 4. V(nLoadedBuffers); 5. V(mutex); } Consumer() { 6. P(nLoadedBuffers); 7. P(mutex); 8. // take 1 item from the buffer 9. V(mutex); 10. V(nFreeBuffers);

4. Does this work? // consumer waits on 0 semaphore nLoadedBuffers = 0; // producer waits on 0 semaphore nFreeBuffers = N; // N >= 2 // one thread waits when another thread is // modifying the buffer semaphore mutex = 1; Producer() { 1. P(nFreeBuffers); 2. P(mutex); 3. // put 1 item in the buffer 4. V(nLoadedBuffers); 5. V(mutex); } Consumer() { 6. P(nLoadedBuffers); 7. P(mutex); 8. // take 1 item from the buffer 9. V(mutex); 10. V(nFreeBuffers);

4. Does this work? Actually, yes. Even if producer thread hits #4 and wakes up a consumer sleeping on #6, the consumer will not be able to enter the critical section until the producer comes back and hits #5