Tutorial 3: Homework 2 and Project 2

Slides:



Advertisements
Similar presentations
Practice Session 7 Synchronization Liveness Deadlock Starvation Livelock Guarded Methods Model Thread Timing Busy Wait Sleep and Check Wait and Notify.
Advertisements

ICS Principles of Operating Systems Lectures 8 and 9 - Deadlocks Prof. Dmitri V. Kalashnikov dvk ics.uci.edu Slides © Prof. Nalini Venkatasubramanian.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Section 3. True/False Changing the order of semaphores’ operations in a program does not matter. False.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Chapter 3 The Critical Section Problem
CY2003 Computer Systems Lecture 05 Semaphores - Theory.
Chapter 6 Concurrency: Deadlock and Starvation
Chapter 3 Deadlocks TOPICS Resource Deadlocks The ostrich algorithm
Chapter 3 Deadlocks - Αδιέξοδα 3.1. Resource
Avishai Wool lecture Introduction to Systems Programming Lecture 5 Deadlocks.
Deadlock Chapter 3 R1 R2 P2P1 Allocated Requested.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Chapter 6 Concurrency: Deadlock and Starvation
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 Processes and Their Scheduling.
1 CS 333 Introduction to Operating Systems Class 7 - Deadlock Jonathan Walpole Computer Science Portland State University.
1 Wednesday, June 28, 2006 Command, n.: Statement presented by a human and accepted by a computer in such a manner as to make the human feel that he is.
Deadlocks. 2 System Model There are non-shared computer resources –Maybe more than one instance –Printers, Semaphores, Tape drives, CPU Processes need.
Concurrent Processes Lecture 5. Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and.
Deadlock CSCI 444/544 Operating Systems Fall 2008.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
1 Concurrency: Deadlock and Starvation Chapter 6.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
Silberschatz, Galvin and Gagne  Operating System Concepts Deadlock and Starvation Deadlock – two or more processes are waiting indefinitely for.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Introduction to Concurrency.
1 Announcements The fixing the bug part of Lab 4’s assignment 2 is now considered extra credit. Comments for the code should be on the parts you wrote.
Chapter 7 – Deadlock (Pgs 283 – 306). Overview  When a set of processes is prevented from completing because each is preventing the other from accessing.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
Operating Systems 软件学院 高海昌 Operating Systems Gao Haichang, Software School, Xidian University 22 Contents  1. Introduction** 
Deadlocks Silberschatz Ch. 7 and Priority Inversion Problems.
1 MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc.
CY2003 Computer Systems Lecture 04 Interprocess Communication.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All.
CS140 Project 1: Threads Slides by Kiyoshi Shikuma.
1 Deadlock. 2 Concurrency Issues Past lectures:  Problem: Safely coordinate access to shared resource  Solutions:  Use semaphores, monitors, locks,
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
This Time - Deadlock Definition Conditions for deadlocks
Deadlock Operating Systems: Internals and Design Principles.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
CS333 Intro to Operating Systems Jonathan Walpole.
Operating Systems COMP 4850/CISG 5550 Deadlocks Dr. James Money.
Deadlocks Mark Stanovich Operating Systems COP 4610.
Deadlocks.  Deadlocks: Occurs when threads are waiting for resources with circular dependencies Often involve nonpreemptable resources, which cannot.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 7: Deadlocks.
Introduction to operating systems What is an operating system? An operating system is a program that, from a programmer’s perspective, adds a variety of.
Lecturer 5: Process Scheduling Process Scheduling  Criteria & Objectives Types of Scheduling  Long term  Medium term  Short term CPU Scheduling Algorithms.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
Lecture 6 Deadlock 1. Deadlock and Starvation Let S and Q be two semaphores initialized to 1 P 0 P 1 wait (S); wait (Q); wait (Q); wait (S);. signal (S);
Deadlock Operating Systems (CC2011NI) -Mr. Pranoy Man Pradhan.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Process Management Deadlocks.
Operating systems Deadlocks.
Background on the need for Synchronization
ITEC 202 Operating Systems
Virtual Memory Networks and Communication Department.
ICS 143 Principles of Operating Systems
COT 5611 Operating Systems Design Principles Spring 2014
Lecture 2 Part 2 Process Synchronization
CS 333 Introduction to Operating Systems Class 7 - Deadlock
Andy Wang Operating Systems COP 4610 / CGS 5765
Chapter 7: Deadlocks.
CSE 153 Design of Operating Systems Winter 2019
CSE 542: Operating Systems
CS444/544 Operating Systems II Scheduler
Presentation transcript:

Tutorial 3: Homework 2 and Project 2

Project 1: Review The class as a whole did well! There is a correlation between lab attendance and project marks. Attendance is not compulsory but is recommended. Remember to utilise of the ECS forums.

Project 1: Commenting Code Code comments should: Justify design decisions. Make vague code understandable. Be concise. Is it necessary to comment the declaration of a loop counter?

Project 1: Code Presentation Why is this important? Improves readability. Improves ‘markability’. Remove commented-out code prior to submission. Be proud of your work!

Homework 2 Q1: 2.22: Does Peterson’s solution to the mutual-exclusion problem shown in Fig. 2-24 (page 125) work when process scheduling is preemptive? How about when it is nonpreemptive?

Homework 2 A: It certainly works with preemptive scheduling. In fact, it was designed for that case. When scheduling is nonpreemtive, it might fail. Consider the case in which turn is initially 0 but process 1 runs first. It will just loop forever and never release the CPU. Preempting the other process allows the two threads to run concurrently. Without preemtion one process can go into the waiting state (busy wait) and the other process will never be able to use the CPU to take its turn.

Homework 2 Q2: 2.26: What is a race condition? A: A race condition is an undesirable situation that occurs when a device or system attempts to perform two or more operations at the same time, but because of the nature of the device or system, the operations must be done in the proper sequence to be done correctly.

Homework 2 Q3: 2.28: The producer consumer problem can be extended to a system with multiple producers and consumers that write (or read) to (from) one shared buffer. Assume that each producer and consumer runs in its own thread. Will the solution presented in Fig. 2-28 (page 131) using semaphores, work for this system?

Homework 2 A: Yes, it will work as is. At a given time instance, only one producer (or consumer) can add (or remove) and item to/from the buffer.

Homework 2 Q4: 6.9: Suppose that there is a resource deadlock in a system. Give an example to show that the set of processes deadlocked can include processes that are not in the circular chain in the corresponding resource allocation graph. A: P1 is not in the cycle but is deadlocked. P1 R2 R3 P2 P3 R1

Homework 2 Q5: 6.28: One way to eliminate circular wait is to have a rule saying that a process is entitled only to a single resource at any moment. Given an example to show that this restriction is unacceptable in many cases. A: Consider a process that needs to cope a huge file from a tape drive to a printer. The entire file cannot be read at one time due to limited memory. Therefore it has to: Acquire tape, copy next portion, release tape, acquire printer, print file, release printer, etc. This will lengthen execution time. As the printer is also released, there is no guarantee it will all be printed on continuous pages.

Homework 2 Q6: 6.35: Explain the difference between deadlock, livelock, and starvation. A: Deadlock occurs when a set of processes are blocked waiting for an event that only some other process (also blocked) can cause. Processes in a livelock are not blocked. Instead, they continue to execute checking for a condition to become true that will never become true. In addition to the resource they are holding, processes in livelock continue to consume CPU time. Starvation occurs when a stream of new processes have higher priority than the process being starved (it never gets to run). Unlike deadlock or livelock, starvation can terminate on its own, e.g. when existing processes with higher priority terminate and no new processes with higher priority arrive.

Project 2: Overview Pintos currently uses FCFS ordering on queues with periodic interrupt to implement RR-like behaviour. Project aim: Implement a priority-based scheduling mechanism. A new version of Pintos is needed: pintos2.tar.gz. Priorities are defined in macros in thread.h. -> Lowest priority = 0, Highest priority = 63.

Project 2: Part 1 Implement priority scheduling for threads. Pre-emption is an important component of this part. A lower priority thread must yield to a higher priority thread. Consider the situations where this may occur. Pass the following tests: alarm­-priority priority­-fifo priority­-preempt priority-­change

Project 2: Part 2 Implement priority scheduling for semaphores, locks and condition variables. The thread waiting for a semaphore (for example) with the highest priority should be woken first. The same goes for locks and condition variables. Pass the following tests: priority-sema priority-condvar Why is there no test for locks? Hint: look at how locks are implemented.

Project 2: Part 3 Implement priority donation. This is used to allow a high priority thread to donate its priority to a low priority thread if it has to wait on it. Say thread A is waiting on a lock held by thread B, A should give its priority to B until the lock is released. Following the release, it should recall the donation. Pass the following tests: priority-donate-one priority-donate-lower priority-donate-sema priority-donate-multiple priority-donate-multiple2

Project 2: Reminders Indicate where your contributions start and end. e.g. /* MY CODE BEGINS */ … /* MY CODE ENDS */ Only submit code that you have edited. -> Do not zip the Pintos codebase and submit that.