Operating Systems. Week 7 5 th Semester, 2012 IN Fei Peng PAI Group University of Fribourg

Similar documents
Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - X Deadlocks - I. University at Buffalo. Synchronization structures

Roadmap. Problems with Semaphores. Semaphores. Monitors. Monitor - Example. Tevfik Koşar. CSE 421/521 - Operating Systems Fall 2012

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - XI Deadlocks - II. Louisiana State University

Roadmap. Bounded-Buffer Problem. Classical Problems of Synchronization. Bounded Buffer 1 Semaphore Soln. Bounded Buffer 1 Semaphore Soln. Tevfik Ko!

Roadmap. Readers-Writers Problem. Readers-Writers Problem. Readers-Writers Problem (Cont.) Dining Philosophers Problem.

5 Classical IPC Problems

Process Management And Synchronization

PROCESS SYNCHRONIZATION

Programming Languages

CS450 OPERATING SYSTEMS FINAL EXAM ANSWER KEY

CSCC 69H3 2/1/13. Today: Deadlock. Remember example from last week? Example of Deadlock. Example: dining philosophers: Not just an OS Problem!

Classical Synchronization Problems. Copyright : University of Illinois CS 241 Staff 1

148 PROCESSES CHAP. 2

Process Synchronization

Chapter 6: Process Synchronization. Operating System Concepts 8 th Edition,

CMPT 300: Operating Systems I Assignment 1

Concurrent Object Oriented Languages

Deadlock Detection & recovery. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

Back to synchronization

CSE306 - Homework2 and Solutions

Yet another synchronization problem

CONCURRENT/DISTRIBUTED PROGRAMMING ILLUSTRATED USING THE DINING PHILOSOPHERS PROBLEM *

CS3502 OPERATING SYSTEMS

Puzzle: Write synchronization code for oxygen and hydrogen molecules that enforces these constraints.

CS 333 Introduction to Operating Systems. Class 6 Monitors and Message Passing. Jonathan Walpole Computer Science Portland State University

Administrivia. Assignments 0 & 1 Class contact for the next two weeks Next week. Following week

4.5 Cigarette smokers problem

Introduction to Operating Systems

CS 537 Lecture 8 Monitors. Thread Join with Semaphores. Dining Philosophers. Parent thread. Child thread. Michael Swift

Sections 01 (11:30), 02 (16:00), 03 (8:30) Ashraf Aboulnaga & Borzoo Bonakdarpour

Deadlock and Monitors. CS439: Principles of Computer Systems September 24, 2018

3 Process Synchronization

The deadlock problem

The Deadlock Lecture

Deadlocks: Part I Prevention and Avoidance Yi Shi Fall 2017 Xi an Jiaotong University

CMSC 330: Organization of Programming Languages. Threads Classic Concurrency Problems

Chapter 6: Process Synchronization

CS 361 Concurrent programming Drexel University Spring 2000 Lecture 14. The dining philosophers problem

CS370 Operating Systems

DEADLOCKS M O D E R N O P E R A T I N G S Y S T E M S C H A P T E R 6 S P R I N G

Project 4: Synchronization

Lesson 6: Process Synchronization

The Dining Philosophers Problem CMSC 330: Organization of Programming Languages

Deadlock and Monitors. CS439: Principles of Computer Systems February 7, 2018

Process Synchronization

Sleeping Barber CSCI 201 Principles of Software Development

Processes The Process Model. Chapter 2. Processes and Threads. Process Termination. Process Creation

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems

CMSC 330: Organization of Programming Languages. The Dining Philosophers Problem

2. The shared resource(s) in the dining philosophers problem is(are) a. forks. b. food. c. seats at a circular table.

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; }

Operating Systems and Networks Course: International University Bremen Date: Dr. Jürgen Schönwälder Deadline:

Interprocess Communication and Synchronization

Synchronization. CSE 2431: Introduction to Operating Systems Reading: Chapter 5, [OSC] (except Section 5.10)

Deadlock Risk Management

Chapter 7: Process Synchronization!

Concurrency and Synchronisation

More Synchronization; Concurrency in Java. CS 475, Spring 2018 Concurrent & Distributed Systems

Chapter 2 Processes and Threads. Interprocess Communication Race Conditions

The dining philosophers problem. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 13

Semaphores. Otto J. Anshus University of {Tromsø, Oslo}

Background. Module 6: Process Synchronization. Bounded-Buffer (Cont.) Bounded-Buffer. Background

Quiz Answers. CS 537 Lecture 9 Deadlock. What can go wrong? Readers and Writers Monitor Example

Lecture 10: Multi-Object Synchronization

CS307 Operating Systems Introduction Fan Wu

Operating Systems Antonio Vivace revision 4 Licensed under GPLv3

Interprocess Communication By: Kaushik Vaghani

Chapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6.

Processes The Process Model. Chapter 2 Processes and Threads. Process Termination. Process States (1) Process Hierarchies

ECS 150 (Operating Systems) Goal To examine what causes deadlock, and what to do about it. Spring Quarter

Chapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition

Operating systems. Lecture 12

Chapter 6: Process Synchronization

Concurrency: Deadlock and Starvation. Chapter 6

Consistency: Strict & Sequential. SWE 622, Spring 2017 Distributed Software Engineering

Deadlock and Starvation

Operating Systems. Operating Systems Sina Meraji U of T

MPRI Course on Concurrency. Lecture 16. The need for randomization: examples in distributed computing and in security

CS370 Operating Systems

CMPT 300 Introduction to Operating Systems

Synchronization Principles II

Resource Allocation and Deadlock Handling

9/30/2014. CS341: Operating System High Level Construct: Monitor Deadlock Conditions Prevention, Avoidance Detection and Recovery

CSE Traditional Operating Systems deal with typical system software designed to be:

9/29/2014. CS341: Operating System Mid Semester Model Solution Uploaded Semaphore ADT: wait(), signal()

The Dining Philosophers with Pthreads

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

Java Simulator for Modeling Concurrent Events

OPERATING SYSTEMS. Deadlocks

Problem Set: Concurrency

CHAPTER 6: PROCESS SYNCHRONIZATION

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Process Synchronization: Semaphores. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

System Software. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 13

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

Concurrent Processes Rab Nawaz Jadoon

Lecture 3: Intro to Concurrent Processing using Semaphores

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 8: Semaphores, Monitors, & Condition Variables

Process Synchronization. studykorner.org

Semaphores. A semaphore is an object that consists of a. methods (e.g., functions): signal and wait. semaphore. method signal. counter.

Transcription:

Operating Systems Week 7 5 th Semester, 2012 IN. 5012 Fei Peng PAI Group University of Fribourg

6.1 Dining Philosophers Problem a. In the solution to the dining philosophers problem (Fig. 2-20), why is the state variable set to HUNGRY in the procedure take_forks? A philosopher may move into the eating state only if neither of his neighbours is eating. Philosopher i's neighbours are defined by the macros LEFT and RIGHT. The program uses an array of semaphores, one per philosopher, so hungry philosophers can block if the needed forks are busy. If a philosopher blocks, neighbours can later see that he is hungry by checking his state in test, so he can be awakened when the forks are available.

6.1 Dining Philosophers Problem b. Consider the put_forks in [Tan 06, Fig.2-20]. Suppose that the variable state[i] was set to THINKING after the two calls to test. How would this change affect the solution for the case of 3 philosophers? For 100 philosophers? For 3 philosophers: The change would mean that after a philosopher stopped eating, neither of his neighbours could be chosen next. With only two other philosophers, both of them neighbours, the system would deadlock. For 100 philosophers: In case of 100 philosopher it won t deadlock. But we lost some parallelism because some philosophers have to wait for a moment.

6.3 The Sleeping Barber Problem Problem description Barber: he checks if there are customers waiting If true The barber cuts his hair, and checks if another customer is waiting. Else The barber sleeps until a customer wakes him up. Customers: the customers enter the shop and check if the barber is sleeping If true He wakes up the barber. Else He waits. // because there are other customers in front of him.

6.3 The Sleeping Barber Problem Deadlock Barber The barber has just finished cutting the hair of a customer. He checks if someone is waiting. Customer At the same time, a customer comes and checks if the barber is sleeping. Because the barber is not sleeping, the customer will wait until the barber comes to check. The barber sees that there is nobody in the waiting room, he starts to sleep. There is a deadlock.

6.4 Scheduling: Ostrich Algorithm a. Explain why most operating systems ignore the possibility of deadlock rather than try to prevent this condition or detect and automatically recover from it. Because deadlock avoidance is very time consuming and resource intensive. Deadlock avoidance would also imply restriction on resources (only on file open at any moment or similar things) which would annoy the user a lot more than occasional deadlocks.

6.4 Scheduling: Ostrich Algorithm b. Most message communication between the processes of the operating system Minix are of the type rendezvous. Explain: 1. How this type of communication can lead to a deadlock This mechanism is based on the concept of sending and receiving messages. It eliminates the buffers storing messages. If a process sends a message to another process that did not call the Receive method, then the sending process is blocked until the receive operation is invoked. In the event that a process loop is formed, the risk of deadlock can occur.

6.4 Scheduling: Ostrich Algorithm 2. How Minix prevent these deadlocks. MINIX requires that the sending of messages can only be made to processes on the right or in the lower layers of the model in MINIX. And the loops are no longer possible.

Hints on Implementing PrioServe 1. Identifying the server process The server process is a normal user process, but we want to give it a special priority. Solution: Add a global variable to glo.h. When making the system call, try to get the PID of the server and keep it in the global variable. When scheduling, check the PID of processes. If it is the server, schedule it to a higher priority queue.

Hints on Implementing PrioServe 2. Change the default queue for user processes. kernel/proc.h USER_Q

Hints on Implementing PrioServe 3. Lower the priority of all queues except the server. kernel/proc.c and / or

Remarks There are a lot of possible implementations. It is your job to work out your solution. Please use these hints critically. Read carefully, again, the Minix book 2.5.4, 2.6.5 and 2.6.10! Also read the source code! You may study from the projects of previous years. But do not copy. The scheduling policy for this year is mostly different.