CS420: Operating Systems. Classic Problems of Synchronization

Similar documents
Dining Philosophers Theory and Concept in Operating System Scheduling

Lecture 9: Tuesday, February 10, 2015

English Level 1 Component 2: Reading

Testing Taste. FRAMEWORK I. Scientific and Engineering Practices 1,3,4,6,7,8 II. Cross-Cutting Concepts III. Physical Sciences

By Carolyn Hunter Dickerson

Activity 2.3 Solubility test

How to Be a Coffee Drinker in the US. Phrases for Ordering

O N E S YO U L L E AT! LESSON 2 & FRUITS ARE THE

Podcast 82 - The Lamington

Name: Monitor Comprehension. The Big Interview

Intro To Water Bath Canning Applesauce

Copyright 2015 by Steve Meyerowitz, Sproutman

7.RP Cooking with the Whole Cup

TRACKS Lesson Plan. Fruit Fruit Rocks Grades 5 8 Girls Club

LEVEL: BEGINNING HIGH

Jim and Betty Held. Stone Hill Winery

Beer Pairing: The Essential Guide From The Pairing Pros Ebooks Free

Argument Paper, MLA Style (Zhang)

LIMPOPO DEPARTMENT OF EDUCATION LAERSKOOL WARMBAD

Jazz s menu offers a variety of home style cooking and traditional pub food, of which they boast, the best chicken parma you ll ever eat.

SENIOR VCAL NUMERACY INVESTIGATION SENIOR VCAL NUMERACY INVESTIGATION Only A Little Bit Over. Name:

Rock Candy Lab Name: D/H

How caffeine affect college students mentality?: I-Search Research Process

IWC Online Resources. Introduction to Essay Writing: Format and Structure

FALL GRADE. Edible SCHOOL GARDEN. Program WORKBOOK STUDENT: VERSION: AUGUST 2016 JHU CAIH

AN OO DESIGN EXAMPLE

How To Root Cuttings In Your Organic Soil System By: Jeremy Silva

Business Entertaining & Dining

Unit 2, Lesson 4: Color Mixtures

4 day food and drink diary

THE EGG-CITING EGG-SPERIMENT!

Cajun Quick (1992) La Meilleure de la Louisiane (1980) New American Light Cuisine (1988) La Cuisine Cajun (1990) Cajun Healthy (1994)

1. Wine Seminar May 27 th 2012

FALL GRADE. Edible SCHOOL GARDEN. Program WORKBOOK ANSWER KEY VERSION: AUGUST 2016 JHU CAIH

STA Module 6 The Normal Distribution

STA Module 6 The Normal Distribution. Learning Objectives. Examples of Normal Curves

Control of treated articles in the Biocidal Products Regulation ECHA Biocides Stakeholders Day 25 June 2013

Table Manners in India

News English.com Ready-to-use ESL/EFL Lessons by Sean Banville

The goal of this project is for you to apply your hilchot brachot knowledge and skills in real life.

Adhesives Teaching Unit

This shop has been compensated by Collective Bias, Inc. and its advertiser. All opinions are mine alone. #GranolaMyWay #CollectiveBias

Objective: Decompose a liter to reason about the size of 1 liter, 100 milliliters, 10 milliliters, and 1 milliliter.

PBL, Projects, and Activities downloaded from NextLesson are provided on an online platform.

Eli Zabar s Recipe for the Perfect Summer Sandwich Is Fast, Easy and Full of Mayonnaise

BBC Learning English 6 Minute English Drinking Tea in the UK

WINE 205 Course Syllabus Fundamentals of Wine: From the Soil to the Table Fall 2016

Preserving The Harvest - Intermediate. Understand: (big idea) How to preserve/used preserved foods

News English.com Ready-to-use ESL / EFL Lessons

Italian Avocado Salad

PROFESSIONAL COOKING, 8TH EDITION BY WAYNE GISSLEN DOWNLOAD EBOOK : PROFESSIONAL COOKING, 8TH EDITION BY WAYNE GISSLEN PDF

Know your food Finding out about dairy foods

As you already know, diet and nutrition play a significant role in managing your COPD. Your diet cannot only help you live a healthier life, but it

Learn to Home Brew: A Series of Tutorials Using Mead

Liquid candy needs health warnings

SAP Fiori - Take Order

GUIDE TO U.S CULTURE AND CUSTOMS.

Italian Avocado Salad

Buttery Garlic Parmesan Rolls

Introduction. (welcome station)

PLEASE CALL THE EXTENSION OFFICE TO REGISTER (606)

Exploring MyPlate with Professor Popcorn

Goals Students will find new ways to add fruits and vegetables to their everyday diets.

#611 ON-SITE TESTING AND EVALUATION

Hostess Training Outline. Significance. Company Name Here

Living Homegrown Podcast Episode 28 Making Homebrew Ginger Ale

Mix it Up: Combining Liquids of Different Temperature

Exploring MyPlate with Professor Popcorn

I Am Going to A Restaurant!

Directions: Read the passage. Then answer the questions below.

Mixtures and Solutions Stations Lesson Plan by Clara Welch Based on FOSS & Kitchen Chemistry by John Bath, Ph. D. and Sally Mayberry, Ed. D.

Darjeeling tea pickers continue strike

We are not a Meatless Monday kind of house. I know you are just shocked by this.

World of Wine: From Grape to Glass

Strawberry DNA. Getting Started. Vocabulary. Strawberry DNA

Honeybees Late Fall Check

Great Niagara Taste Test Activity Centre. Presenter s Script

100 Days of Real Food Cookbook Review

SUCCESSFUL SLOW COOKING

Corking Row over Sour Grapes

Instruction (Manual) Document

Answering the Question

Pot Pie Ashtrays: Breaking The Cycle Of Child Abuse By Edward Sternisha, Esq.

By Peter Spyros Goudas

Slide to a Slice. P I E P I E Start P I E P I E P I P I E E. P Persuade I Inform E - Entertain

. Children will be able to identify a vegetable they can eat at home.

GLOBALIZATION UNIT 1 ACTIVATE YOUR KNOWLEDGE LEARNING OBJECTIVES

A WORLD FIRST FOR HIBISCUS (WE THINK)

Greek Pasta Salad. Description

News English.com Ready-to-use ESL / EFL Lessons

Jen s Five Favorite Healthy + Delicious Green Smoothies

Grade: Kindergarten Nutrition Lesson 4: My Favorite Fruits

Injection, Modularity, and Testing

Restaurant Review 26 One-19 North February 7, 2015

Experimental Procedure

Bertrand Chemel [Photos: Gerry Suchy/Eater.com]

Filet mignon is prized around the world as quality beef, the kind that fetches high prices and the praise of meat lovers around the world.

4 th Grade 1 st 6 Weeks SCIENCE Test

Experimental Procedure

PARABLE OF THE SOWER

Transcription:

Classic Problems of Synchronization James Moscola Department of Physical Sciences York College of Pennsylvania Based on Operating System Concepts, 9th Edition by Silberschatz, Galvin, Gagne

Classical Problems of Synchronization Classical problems used to test newly-proposed synchronization schemes - Bounded-Buffer Problem! - Readers and Writers Problem! - Dining-Philosophers Problem 2

Bounded-Buffer Problem (Producer/Consumer Problem) In a generalized Bounded Buffer problem, N buffers, each can hold one data item Utilize three semaphores to control access to buffer between the producer and the consumer - Semaphore mutex locks access to critical region of code where buffer is modified Initialized to the value 1 - Semaphore full keeps track of how many items are actually in the buffer Initialized to the value 0 - Semaphore empty keeps track of how many available slots there are in the buffer Initialized to the value N 3

Bounded Buffer Problem (Cont.) Producer Process do { // produce an item wait (empty); // inited to N wait (mutex); // add item to the buffer signal (mutex); signal (full); } while (TRUE);! Consumer Process do { wait (full); // full inited to 0 wait (mutex); // remove item from buffer to nextc signal (mutex); signal (empty); // consume the item in nextc } while (TRUE); 4

Dining-Philosophers Problem Statement Five philosophers spend their lives thinking and eating while sitting at a round table around a bowl of rice A chopstick is placed between each philosopher Philosophers cannot interact with their neighbors Each philosopher will think and occasionally eat - When ready to eat a philosopher will try to pick up 2 chopsticks (one at a time) so he can eat some rice - A philosopher needs 2 chopsticks to eat - When done eating a philosopher will put down each chopstick, one at a time How can the philosophers sit and eat together without anyone starving? - Think of each chopstick as a semaphore 5

Dining-Philosophers Issues Possible Solution?? - Instruct each philosopher to behave as follows: Think until the left chopstick is available; when it is pick it up Think until the right chopstick is available; when it is pick it up Eat some rice Put the left chopstick down Put the right chopstick down Go back to thinking Why might this not work? 6

Dining-Philosophers Issues do { wait ( chopstick[i] ); wait ( chopstick[ (i + 1) % 5] );... // eat... signal ( chopstick[i] ); signal ( chopstick[ (i + 1) % 5] );... // think... } while (TRUE); 7

Dining-Philosophers Issues Possible Solution?? - Instruct each philosopher to behave as follows: Think until the left chopstick is available; when it is pick it up Think until the right chopstick is available; when it is pick it up Eat some rice Put the left chopstick down Put the right chopstick down Go back to thinking Why might this not work? - If each philosopher picks up his left chopstick at the same time, then they all sit waiting for the right chopstick forever (i.e. deadlock) 8

Dining-Philosophers Issues How about telling the philosophers to put down their left chopstick if they ve held it for some period of time? - If the timing is just right, the philosophers may end up in livelock The philosophers continue to alternate between thinking and (attempting) to eat, but if the philosophers all try to pick up their chopsticks at the same time, then they will all put them back down at the same time. This cycle will continue until the philosophers starve 9

Dining-Philosophers Solutions The Conductor Solution - Add a waiter to the table - A philosopher must ask the waiters permission before picking up any chopsticks - The waiter knows how many chopsticks are in use and can therefore arbitrate and ensure that deadlock does not occur 10

Dining-Philosophers Solutions The Chandra-Misra Solution - Does not require a waiter or any other central authority - Breaks the rules a little bit and allows philosophers to talk to their neighbors - Proposed Solution: For every pair of philosophers contending for a chopstick create a chopstick and give it to one of them When a philosopher wants to eat, he must obtain two chopsticks, so he requests one chopstick from each of his neighbors - The philosopher may already have one and therefore will only need to request one When a philosopher with a chopstick gets a request from his neighbor he keeps the chopstick if it is clean, but cleans it and gives it up if it is dirty After a philosopher has eaten, both his chopsticks are dirty. If another philosopher had requested his chopstick, he cleans the chopstick and passes it over. 11

Dining-Philosophers Solutions The Chandra-Misra Solution (Cont.) - This solution can be used for an arbitrarily large number of philosophers - Solves the problem of starvation with the clean/dirty chopsticks Gives preference to the most starved philosopher A philosopher that has eaten must give up his chopsticks 12

Problems with Semaphores Incorrect use of semaphore operations (bad programming... maybe by someone else): - signal (mutex). wait (mutex) -- wrong order! - wait (mutex) wait (mutex) -- decrement TWO resources! - Omitting of wait (mutex) or signal (mutex) (or both) -- UGH! Deadlock and starvation 13