Homework 6 Sarah Diesburg Operating Systems CS 3430.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

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: Monitors 1 Monitors (C.A.R. Hoare) higher level construct than semaphores a package of grouped procedures, variables and data i.e. object.
Module R2 Overview. Process queues As processes enter the system and transition from state to state, they are stored queues. There may be many different.
1 Operating Systems, 122 Practical Session 5, Synchronization 1.
Lab2: Semaphores and Monitors. Credits Material in this slide set is from G. Andrews, “Foundation of Multithreaded, Parallel, and Distributed Programming”,
1 Mutual Exclusion: Primitives and Implementation Considerations.
1 Semaphores and Monitors: High-level Synchronization Constructs.
Multi-Object Synchronization. Main Points Problems with synchronizing multiple objects Definition of deadlock – Circular waiting for resources Conditions.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
CS444/CS544 Operating Systems Synchronization 2/21/2007 Prof. Searleman
Monitors CSCI 444/544 Operating Systems Fall 2008.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Monitors: An Operating System Structuring Concept
Operating System Program 5 I/O System DMA Device Driver.
Parallel Processing (CS526) Spring 2012(Week 8).  Thread Status.  Synchronization in Shared Memory Programming(Java threads ) ◦ Locks ◦ Barriars.
Programming Models using Windows* Threads Intel Software College.
Monitor  Giving credit where it is due:  The lecture notes are borrowed from Dr. I-Ling Yen at University of Texas at Dallas  I have modified them and.
Multithreaded Web Server.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Not Another Completely Heuristic Operating System
Multithreading : synchronization. Avanced Programming 2004, Based on LYS Stefanus’s slides slide 4.2 Solving the Race Condition Problem A thread must.
Semaphores, Locks and Monitors By Samah Ibrahim And Dena Missak.
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.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
Suggested Exercises 5. Question #1 Find a creative/funny example of synchronization that can demonstrate the difficulty of developing a monitor-based.
11/18/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam.
Linux Kernel Management. Module 9 – Kernel Administration ♦ Overview The innermost layer of Linux operating system is the kernel, which is a thin layer.
Project 2 kthreads, concurrency, shuttle. Highlevel overview User space –program wants to control the shuttle simulation by sending requests. –start_shuttle()
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
1 Condition Variables CS 241 Prof. Brighten Godfrey March 16, 2012 University of Illinois.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Synchronization Emery Berger and Mark Corner University.
CPS110: Thread cooperation Landon Cox. Constraining concurrency  Synchronization  Controlling thread interleavings  Some events are independent  No.
1 Previous Lecture Overview  semaphores provide the first high-level synchronization abstraction that is possible to implement efficiently in OS. This.
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.
Homework-6 Questions : 2,10,15,22.
Concurrency: Locks and synchronization Slides by Prof. Cox.
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.
pThread synchronization
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Tutorial 2: Homework 1 and Project 1
CS703 - Advanced Operating Systems
Sarah Diesburg Operating Systems COP 4610
CIS Operating Systems Synchronization
Monitors, Condition Variables, and Readers-Writers
HW1 and Synchronization & Queuing
CSCI 511 Operating Systems Chapter 5 (Part C) Monitor
Uniprocessor Lock Implementation
Sarah Diesburg Operating Systems COP 4610
Kernel Structure and Infrastructure
CS 6560 Operating System Design
Critical section problem
CSE 451 Autumn 2003 Section 3 October 16.
Implementing Mutual Exclusion
CS 6560 Operating System Design Kernel Loadable Modules
Monitor Giving credit where it is due:
Implementing Mutual Exclusion
Homework 4.
CSE 153 Design of Operating Systems Winter 19
CS333 Intro to Operating Systems
Don Porter Portions courtesy Emmett Witchel
Sarah Diesburg Operating Systems CS 3430
CPS110: Thread cooperation
Single-Core Lock Implementation
Review The Critical Section problem Peterson’s Algorithm
Sarah Diesburg Operating Systems CS 3430
Presentation transcript:

Homework 6 Sarah Diesburg Operating Systems CS 3430

Helicopter Problem A helicopter ride has five seats, and it always carries a full load. Use lock(s) and condition variable(s) to write a procedure PersonArrives(), which is called whenever a person (thread) arrives. Once the load is full, one person (thread) should call UpAndAway(), and five threads should return from PersonArrives().  There should be no undue waiting: the helicopter should depart as soon as it has a full load.

Helicopter Problem int queue = 0; condition okToGo = NULL; Lock lock = FREE; PersonArrives() { lock.Acquire(); ++queue; if (queue < 4) { okToGo.wait(&lock); } else { GoGoGo(); queue = 0; okToGo.Signal(&lock); } lock.Release(); }

Helicopter Problem int queue = 0; condition okToGo = NULL; Lock lock = FREE; PersonArrives() { lock.Acquire(); ++queue; if (queue < 5) { okToGo.wait(&lock); } else { UpAndAway();= 0; okToGo.Signal(&lock); } lock.Release(); }

Helicopter Problem int queue = 0; condition okToGo = NULL; Lock lock = FREE; PersonArrives() { lock.Acquire(); ++queue; if (queue < 5) { okToGo.wait(&lock); } else { UpAndAway(); okToGo.Signal(&lock); queue = 0; } lock.Release(); }

Proving Correctness Mutual exclusion  All shared variables are locked e.g., queue  Signal() and Wait() are invoked between lock.Acquire() and lock.Release()

Proving Correctness Liveness  Maximum of 4 threads in okToGo.wait()  Every 5 th thread wakes up exactly four threads already waiting in okToGo.wait()  Additional threads wait at lock.Acquire()  As long as we have 5n threads, every thread will make progress

Proving Correctness Fairness  As long as we have FIFO queues at lock.Acquire()  The queuing policy at okToGo.wait() does not matter, since all four waiting threads will be awakened  As long as we have 5n threads  Every thread will get its chance

Common Pitfalls int queue = 0; condition okToGo = NULL; Lock lock = FREE; PersonArrives() { lock.Acquire(); ++queue; if (queue < 5) { okToGo.wait(&lock); } else { UpAndAway(); okToGo.Signal(&lock); queue = 0; lock.Release(); } Wait() requires lock on return No lock.Release()

Common Pitfalls int queue = 0; condition okToGo = NULL; Lock lock = FREE; PersonArrives() { lock.Acquire(); ++queue; lock.Release(); if (queue < 5) { lock.Acquire(); okToGo.wait(&lock); lock.Release(); } else { lock.Acquire(); UpAndAway(); okToGo.Signal(&lock); queue = 0; lock.Release(); } Unprotected states Multiple threads may wait here

Kernel Modules A kernel module is driver code that is dynamically loaded into the driver when it is needed  Also can be unloaded The kernel is an executable file  Can contain built-in driver code, but makes the executable bigger

Module Commands insmod – insert a module into the running kernel rmmod – remove a module from the running kernel modprobe – inserts a module, along with all other modules it depends on  Only using insmod for our project