Lecture 9: Tuesday, February 10, 2015

Similar documents
A Note on H-Cordial Graphs

CS420: Operating Systems. Classic Problems of Synchronization

Caffeine And Reaction Rates

Dining Philosophers Theory and Concept in Operating System Scheduling

6.2.2 Coffee machine example in Uppaal

Week 5 Objectives. Subproblem structure Greedy algorithm Mathematical induction application Greedy correctness

CS 322: (Social and Information) Network Analysis Jure Leskovec Stanford University

Chapter 1: The Ricardo Model

The Column Oven Oven capabilities Oven safety Configuring the oven Making a temperature-programmed run Fast chromatography

Quotient Cordial Labeling of Graphs

LEAN PRODUCTION FOR WINERIES PROGRAM

STABILITY IN THE SOCIAL PERCOLATION MODELS FOR TWO TO FOUR DIMENSIONS

John Perry. Fall 2009

Chapter 3. Labor Productivity and Comparative Advantage: The Ricardian Model. Pearson Education Limited All rights reserved.

Lesson 23: Newton s Law of Cooling

HW 5 SOLUTIONS Inference for Two Population Means

Appendix A. Table A.1: Logit Estimates for Elasticities

-- Final exam logistics -- Please fill out course evaluation forms (THANKS!!!)

FREQUENTLY ASKED QUESTIONS (FAQS)

Anaerobic Cell Respiration by Yeast

3-Total Sum Cordial Labeling on Some New Graphs

COURT OF MASTER SOMMELIERS OCEANIA

BRD BREWERS RESOURCE DIRECTORY

Chapter 3. Labor Productivity and Comparative Advantage: The Ricardian Model

Preview. Chapter 3. Labor Productivity and Comparative Advantage: The Ricardian Model

LESSON 5 & DARK GREEN

P O L I C I E S & P R O C E D U R E S. Single Can Cooler (SCC) Fixture Merchandising

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

Evaluation copy. Falling Objects. Experiment OBJECTIVES MATERIALS

Investigation 1: Ratios and Proportions and Investigation 2: Comparing and Scaling Rates

Investigation 1: Ratios and Proportions and Investigation 2: Comparing and Scaling Rates

HOME ROASTER COMPETITION ENTRY FORMS GENERAL REGULATION

Introduction to Management Science Midterm Exam October 29, 2002

Illinois Geometry Lab. Percolation Theory. Authors: Michelle Delcourt Kaiyue Hou Yang Song Zi Wang. Faculty Mentor: Kay Kirkpatrick

Preview. Introduction (cont.) Introduction. Comparative Advantage and Opportunity Cost (cont.) Comparative Advantage and Opportunity Cost

Preview. Introduction. Chapter 3. Labor Productivity and Comparative Advantage: The Ricardian Model

Recursion. John Perry. Spring 2016

Calibrate grill heat zones Monthly GR 1 M1

Route List Configuration

Which of your fingernails comes closest to 1 cm in width? What is the length between your thumb tip and extended index finger tip? If no, why not?

INTERNATIONAL UNDERGRADUATE PROGRAM BINA NUSANTARA UNIVERSITY. Major Marketing Sarjana Ekonomi Thesis Odd semester year 2007

Activity 10. Coffee Break. Introduction. Equipment Required. Collecting the Data

KEY. Chemistry End of Year Cornerstone Assessment: Part A. Experimental Design

Processing of Pasteurized Market Milk

Square Divisor Cordial, Cube Divisor Cordial and Vertex Odd Divisor Cordial Labeling of Graphs

Biologist at Work! Experiment: Width across knuckles of: left hand. cm... right hand. cm. Analysis: Decision: /13 cm. Name

FOR PERSONAL USE. Capacity BROWARD COUNTY ELEMENTARY SCIENCE BENCHMARK PLAN ACTIVITY ASSESSMENT OPPORTUNITIES. Grade 3 Quarter 1 Activity 2

Roya Survey Developers Bil Doyle Brad Johns Greg Johnson Robin McNal y Kirsti Wal Graduate Consultant Mohammad Sajib Al Seraj Avinash Subramanian

Chapter 3 Labor Productivity and Comparative Advantage: The Ricardian Model

MISSION POINT LIGHTHOUSE FRIENDS 2018 WINE LABEL ART COMPETITION ANNOUNCEMENT

2018 Foods Department

Economics 101 Spring 2016 Answers to Homework #1 Due Tuesday, February 9, 2016

P O L I C I E S & P R O C E D U R E S. I.C.E. In-store Merchandising

Copyright 2015 by Steve Meyerowitz, Sproutman

Specify the requirements to be met by agricultural Europe Soya soya bean collectors and Europe Soya primary collectors.

LEVEL: BEGINNING HIGH

CMC DUO. Standard version. Table of contens

Relation between Grape Wine Quality and Related Physicochemical Indexes

TEACHER NOTES MATH NSPIRED

COMPETITION ENTRY FORMS GENERAL REGULATION

Preview. Introduction. Chapter 3. Labor Productivity and Comparative Advantage: The Ricardian Model

INFLUENCE OF THIN JUICE ph MANAGEMENT ON THICK JUICE COLOR IN A FACTORY UTILIZING WEAK CATION THIN JUICE SOFTENING

Photosynthesis: How do plants get energy? Student Advanced Version

Falling Objects. computer OBJECTIVES MATERIALS

Benchmarking and Best Practices Survey Results

TEST PROJECT. Server Side B. Submitted by: WorldSkills International Manuel Schaffner CH. Competition Time: 3 hours. Assessment Browser: Google Chrome

Thought Starter. European Conference on MRL-Setting for Biocides

west australian wine industry sustainable funding model

Properties of Water TEACHER NOTES. Earth: The Water Planet Laboratory Investigation. Key Concept. Alternate Materials.

Introduction to the Practical Exam Stage 1

INSTRUCTION MANUAL FOR BUILT-IN OVENS

OPTIMA PLUS-SOFT PLUS

Pg. 2-3 CS 1.2: Comparing Ratios. Pg CS 1.4: Scaling to Solve Proportions Exit Ticket #1 Pg Inv. 1. Additional Practice.

Product Consistency Comparison Study: Continuous Mixing & Batch Mixing

Route List Setup. About Route List Setup

Cut Rite V9 MDF Door Library

Experience with CEPs, API manufacturer s perspective

A CLT for winding angles of the paths for critical planar percolation

Sustainable Coffee Challenge FAQ

STA Module 6 The Normal Distribution

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

PRODUCT REGISTRATION: AN E-GUIDE

BRD BREWERS RESOURCE DIRECTORY

Napa Green Certified Land Certification Mark Usage Standards

Sponsored by: Center For Clinical Investigation and Cleveland CTSC

Experiment 7: The Clock Reaction

Planning: Regression Planning

SPLENDID SOIL (1 Hour) Addresses NGSS Level of Difficulty: 2 Grade Range: K-2

Advancing Agriculture Grape Industry Development Program

There s More Than One Way to Serve Breakfast

Supermarket Industry Concerns and Questions - FDA Menu Labeling Regulation

Fungicides for phoma control in winter oilseed rape

Chardonnay Winemaking insights in Margaret River. Glenn Goodall

THE EGG-CITING EGG-SPERIMENT!

STATE OF MICHIGAN DEPARTMENT OF LICENSING AND REGULATORY AFFAIRS LANSING

Recent U.S. Trade Patterns (2000-9) PP542. World Trade 1929 versus U.S. Top Trading Partners (Nov 2009) Why Do Countries Trade?

COURSE FOD 3040: YEAST PRODUCTS

DAIRY REIMAGINED A RESOURCE GUIDE BOOK AVENIR NEXT CONDEN

Plan for Change. Confidence through Development. A Useful Guide to Report Writing Example Report. Barchester Manufacturing Limited

Transcription:

Com S 611 Spring Semester 2015 Advanced Topics on Distributed and Concurrent Algorithms Lecture 9: Tuesday, February 10, 2015 Instructor: Soma Chaudhuri Scribe: Brian Nakayama 1 Introduction In this lecture we discuss the Dining Philosopher s Problem. We show that the Dining Philosopher s algorithm cannot be symmetric or anonymous (defined below). We then introduce the Right-Left algorithm. Definition 1 (Symmetry) An algorithm is symmetric if it is the same for all processes. Definition 2 (Anonymity) An algorithm is anonymous if a processor does not know its index. Anonymity implies symmetry. Technical note: The queue s for the chopsticks below can be implemented using the Read- Modify-Write (RMW) objects discussed in Lecture 7. 2 Dining Philosophers Problem The dining philosophers (DP) problem is described as a set of processors in a ring, where each shares a resource (encoded as a RMW FIFO queue) with each of its adjacent neighbors. In order to enter the critical section, a philosopher needs both resources. Thus, any algorithm for the philosophers can be summarized as follows: 1. REM - thinking. 2. ENTRY - wants to eat. Tries to pick up chopsticks. 3. CS - has both chopsticks; eating. 4. EXIT - release chopsticks. 3 Symmetry and the DP Problem 3.1 No Symmetric (or Anonymous) Solution Theorem 1 There is no symmetric solution to the DP problem. 1

P1 f1 P2 f5 f2 P5 P3 f4 P4 f3 Figure 1: The Dining Philosophers: Each philosopher P i is sharing a resource f i shown by an edge between the two. The philosophers and the resources form a ring topology. Proof: Suppose for contradiction that there is a symmetric algorithm A for n processors. Consider an execution α for A that begins with all processors in the same state and with all shared variables in the same initial value. Execution α proceeds in round robin fashion for some number of steps n. (e.g. 1, 2,..., n, 1, 2,...n,... etc.) Since each processor has the same state at the beginning of a round (and philosophers cannot send messages to each other), they will read/write the same value in their shared registers, and end in the same state at the end of the round. By induction, we can show that after any number of rounds, all processors will be in the same state. So, if any processors enter CS after some round k, to satisfy progress then all processors will enter CS after round k, violating exclusion. Thus there is no symmetric solution. 3.2 A wrong DP Algorithm Examine the following symmetric algorithm. Each procedure after entering ENTRY waits first for the right chopstick and then the left chopstick after. Getting both chopsticks, it enters CS. On exit, it releases both chopsticks and enters REM. All processors then take the following steps: 1. All processors enter ENTRY. 2. All processors grab right chopsticks. 3. All processors wait for left chopstick. Thus progress fails. 2

4 Right-Left Dining Philosopher s Algorithm 4.1 Introducing the Algorithm The Right-Left (RL) Dining Philosopher s Algorithm guarantees progress as well as no starvation. It follows from thm 1 that the RL algorithm is not symmetric. Some processors seek the left chopstick first, while some seek the right chopstick first. It may, however, create long waiting chains. Waiting time is proportional to the length of the waiting chain, which is proportional to the number of philosophers. Further on, we will need to guarantee a small bound on the length of the waiting chain. Idea for the RL Algorithm Each chopstick has a shared variable, which is accessible via a FIFO queue of the two adjacent processors. For an even number of processors the algorithm works as follows: 1. Odd-numbered processors P i (starting with P 1 ) seek the right chopstick f i 1 first. 2. Even-numbered processors P i seek the left chopstick f i first. 3. Processors seek a chopstick by placing their index at the end of a queue. 4. Processors obtain chopstick when their index reaches the front of the queue. 5. Processors enter CS after obtaining chopsticks. 6. On exit processors remove their indices from chopstick queues. For an odd number of processors the algorithm works similarly: 1. Processors P 1, P 2..., P n work as defined by the RL algorithm for an even number of processors. 2. The last processor P n+1 where n = 2k, k N, will seek the right chopstick f n first and the left chopstick f n+1 second. 3. The processors then proceed through the algorithm as if there were an even number of processors. Note that the odd implementation of the algorithm will not affect the following proof for mutual exclusion. The proof for mutual exclusion relies on the definition of the Dining Philosopher s problem and is independent of the number of philosophers. The time complexity for processors P n and P n+1 in the odd case will be more, and the time complexity for processor P 1 will be less as shown in lemma 5, but all other processors will not be affected. 3

Lemma 2 Each processor P i is in the head of queues for chopsticks f i and f i+1 while processor P i is in CS. Proof: P i must be at the head of the queues for both shared resources f i and f i+1 according to the definition of the Dining Philosopher s Problem. Theorem 3 Mutual Exclusion is satisfied by the RL algorithm. Proof: Suppose for contradiction that there exists two adjacent processors P i, P i+1 such that both are in CS at the same time. Let the variable f i+1 be shared between P i, P i+1, informally called a chopstick and encoded as RMW FIFO queue. According to lemma 2, if processor P i is in CS, it is in front of the queue for chopstick f i+1, and it will leave CS before P i+1 can enter CS (due to the properties of queues given in lecture 7, theorem 8). Thus, suppose processor P i+1 is in CS. Again, if processor P i+1 is in CS, it is in front of the queue for chopstick f i+1, and it will leave CS before P i can enter CS. 4.2 Time Complexity of Right-Left Dining Philosopher s Algorithm Let l be the upper bound on a time step of each processor, and let c be the upper bound on time a process is in CS. Lemma 4 In the Right-Left Dining Philosopher s Algorithm, the time between when a processor enters ES and enters CS is at most 3c + 18l for all processors when there are an even number of processors. Proof: When a processor (i.e. philosopher) is at the head of a queue for a resource (i.e. chopstick) f i, we say the processor has the chopstick f i. If a processor has the chopstick when it adds itself to the queue, we say the processor knows it has the chopstick. The whole operation of adding itself to the queue and knowing it has the chopstick takes l time due to the properties of the RMW registers composing the queues. If a processor does not have the chopstick after it adds itself to the queue (taking l time) it must perform another check to know if it has a chopstick after it attains it, which takes an additional l time. Let some processor i enter ENTRY. Let t be the time i takes to enter CS. A chopstick between 2 processors is either chosen first for both or second for both, with the exception of when we have an odd number of processors. Lets examine the even case. This implies that the max waiting chain is 2. Let s be the max time between obtaining the first chopstick and entering CS. After time l, processor i tries to get the first chopstick f m. If available, then the total time needed is equal to l + s. Otherwise, neighbor j has its first chopstick f m when i tries to get the first chopstick. If neighbor j has f m, recall that it takes processor i l time to add itself to f m s queue, even though it does not attain the chopstick. Furthermore, neighbor j will take s time to enter the 4

CS, c time in CS, and l time before putting the chopstick down at which point i will finally have the chopstick. After neighbor j releases f m, it will take processor i s time to enter CS. Thus, in the worst case we need l + s + c + l + s time for processor i to enter CS. It then follows that t max(l + s, c + 2l + 2s), and t c + 2l + 2s. Next, examine time s. The best case is s = 3l. The best case can be explicated as follows: when both chopsticks are available, processor i needs l time to know it has its first chopstick (which is true since i has the first chopstick by the definition of s), l time to attain and know it has its second chopstick, and l time to enter CS. Otherwise s = c + 8l: l to know we have the first chopstick. l time to put i in the second chopstick f n s queue (and realize we do not have the second chopstick). (2l + c + 2l) for the time another adjacent processor k takes to get into and out of CS. We need l to know we have k s second chopstick and l to enter CS. It takes k c time to get out of CS Finally we need l for dropping its first chopstick, and l to drop its second chopstick f n in EXIT. l for processor i to know it has the second chopstick f n. l to enter CS. Thus s c + 8l. Substituting this into the equation for T results in: t c + 2l + 2s t c + 2l + 2c + 16l t 3c + 18l Thus the maximum time between when a processor enters ES and enters CS is 3c + 18l. Intuitively, one can see that up to three processors are entering CS before processor i. The processors are 1. the processor j sharing i s high priority chopstick, 2. the processor sharing j s low priority chopstick, and 3. the processor sharing i s low priority chopstick. Lemma 5 For the odd case of the Right-Left Dining Philosopher s Algorithm, the time between when a processor enters ES and enters CS is at most 4c+21l for processors P n and P n+1, 2c+15l for processor P 1, and 3c + 18l for P 2, P 3...P n 1. Proof: Examine processor P n+1. If neighbor P 1 or P n has the chopstick, then they will take s time to enter the CS, c time in CS, and l time before putting the chopstick down. Let t n+1 be the time it takes P n+1 to get into CS. It then follows that t n+1 max(l + s, 2c + 5l + 2s), and t n+1 2c + 5l + 2s. We need c + l + s time for processors P 1 and P n, and another 3l for processor P n+1. Time s remains the same as in lemma 4. Thus: 5

t n+1 4c + 21l Examine processor P n. Let t n be the time it takes P n to get into CS. t n max(l+s, 2c+5l+2s), where c + 2l + 2s comes from P 1 and P n+1 similar to the even case, and 3l + c for P n. This will also lead to: t n 4c + 21l Examine processor P 1. Let t 1 be the time for P 1 to enter CS. t 1 max(l + s, c + 7l + s), where l + s is the time it takes for P n+1 to enter and drop its chopstick and 3l + c is the time it takes for P 2 to enter CS and drop its chopstick, and 3l is the time it takes for P 1 to check both chopsticks and enter CS. Substituting for s we get: t 1 2c + 15l For all other processors P i, the adjacent processors that can enter CS during P i s time in ES are congruent to the processor i used to prove lemma 4. Their max times remain the same. 6