the problem if one or more philosophers try to to e at
play

The problem If one or more philosophers try to to e at - PDF document

The problem If one or more philosophers try to to e at then one of them ev en tually after a nite time succeeds No Deadlo c k The ab o v e prop ert y do es not pro vide an y guaran tee


  1. � � The problem If one or more philosophers try to to e at � then one of them ev en tually after a �nite time succeeds� No Deadlo c k The ab o v e prop ert y do es not pro vide an y guaran tee on an individual basis since a pro cessor ma y try to eat and y et fail� since it alw a ys b ypassed b y other philosophers� What w e w ould lik e to ha v e is a stronger prop ert y � whic h implies no deadlo c k� If a philosopher wishes to eat� No Starv ation then it will ev en tually after a �nite time succeed as long as no philosopher k eeps eating forev er� W e assume that eac h philosopher eats for at most time units� �� � � �� � � DS I I L��� Philippas Tsigas

  2. � � Symmetry W e sa y that a solution to a distributed problem is symmetric if� � all pro cesses are iden tical �nothing that distinguishes one computer from the other�� � all pro cesses run the same co de � all shared �or lo cal� v ariables ha v e the same input v alue� � � DS I I L��� Philippas Tsigas

  3. � � Imp ossibilit y Result There is no symmetric solution to the dinning philosophers problem Assume for the purp ose of con tradiction Pro of that there is a solution A � Consider a �round�robin� execution of in � A whic h �rst philosopher p mak es its �rst step � then p � � � then p � W e can pro v e b y induction � n that after this �rst round all philosophers are going to b e in the same state and all links are going to ha v e the same messages� No w w e can pro v e again b y induction on the n um b er of rounds that at the end of eac h round all philosophers are alw a y going to b e in the same state� The last one means that if philosopher p at i some p oin t starts eating its neigh b ours will start eating together with him �b y the end of the resp ectiv e round� Contr adiction Accessible � � common resources are referred n y the pro cesses with their lo cal DS I I L��� Philippas Tsigas

  4. � � names � � DS I I L��� Philippas Tsigas

  5. � � Righ tLeft DP Proto col F or simplicit y n is ev en W e giv e di�eren t proto cols to the philosophers� one for the philosophers that w e call with o dd indices and one for those with ev en indices� The basic strategy is v ery simple� Odd�numb er e d philosophers seek their righ t fork �rst philosophers seek their left fork Even�numb er e d �rst A philosopher seeks a c hopstic k b y putting its id at the end of that c hopstic k�s queue� The philosopher obtains the c hopstic k when its index reac hes the fron t of that c hopstic k�s queue� When a philosopher �nishes eating� it returns b oth c hopstic ks b y remo ving its index from their queues� � � DS I I L��� Philippas Tsigas

  6. � � Time Complexit y IDEA� A c hopstic k b et w een t w o philosophers is either the �rst c hopstic k for b oth or the second c hopstic k for b oth� Roughly � � � � �� �� Time Complexit y� � � DS I I L��� Philippas Tsigas

  7. � � Same co de to the pro cesses Y ou can ask from y our system �philosophers� to get unique names from the range �� ��n � ��� But this is not going to b e b ecause the lo c al philosophers ha v e to learn n � Y ou can ask from y our pro cesses to get a color from the set of colours P � f bl ack � w hite g � so that no t w o neigh b ours get the same color� Can this b e done� � � DS I I L��� Philippas Tsigas

  8. � � Dinning Philosophers Cn t� W e can ha v e a to the dinning solution philosophers problem if w e start with a Black � White coloring of the ring� The Black � White coloring can b e seen as a prepro cessing phase though that need to b e done from the system when philosophers lea v e the table or new ones are joining� On aver age if b et w een t w o coloring phases pro cesses sp end time prop ortional to at the n table ��� � � DS I I L��� Philippas Tsigas

  9. � � Philosophers vs� Chopstic ks Let us ha v e lo ok at the algorithm that w e describ ed in the previous lecture� The algorithm lo ok ed lik e this� � Hungry� � Get a color if y ou do not Black � White ha v e one� � If y ou are seek righ t c hopstic k �rst Black � if y ou are seek left c hopstic k �rst White � After �nish eating put the c hopstic k bac k � � DS I I L��� Philippas Tsigas

  10. � � Philosophers vs� Chopstic ks Cn t� A new algorithm� � Hungry� � Giv e a Black � White �consisten t� color to y our c hopstic ks if y ou ha v e not done that� � Seek Black c hopstic k �rst The of the �rst algorithm Remem b er� ide a w as that a c hopstic k b et w een t w o philosophers is either the �rst �here blac k� c hopstic k for b oth or the second �here white� c hopstic k for b oth� � � DS I I L���� Philippas Tsigas

  11. � � Ho w do I color c hopstic ks� � � DS I I L���� Philippas Tsigas

  12. � � Resource Allo cation Generalising the Dinning Philosophers A resource allo cation problem consists of a �nite set of r esour c es and some comp eting esses � pr o c Pro cesses request access to the resources from time to time in order to execute a co de segmen t called critic al se ction � Up on b eing gran ted all the requested resources� a pro cess pro ceeds to use them and ev en tually relinquishes them� Requiremen ts� �� No resource should b e Mutual exclusion accessed b y more than one pro cess at the same time� �� As long as pro cesses do No Starv ation not fail� no pro cess should w ait forev er for requested resources� � � DS I I L���� Philippas Tsigas

  13. � � Resource Allo cation Solution W e generalise in a straigh tforw ard w a y the Righ tLeft Dinning philosophers algorithm to an arbitrary resource allo cation problem� W e �rst construct the Graph � Resource � The no des of this graph represen t the resources � There is a no de from one no de to another if there is some pro cess that uses b oth the resources� � � DS I I L���� Philippas Tsigas

  14. � � Coloring again W e no de�color the r esour c e gr aph � � DS I I L���� Philippas Tsigas

  15. � � The Generalisation Eac h pro cess seeks its resources in increasing order according to the total ordering constructed b y the coloring� A pro cess seeks a resource b y putting its index at the end of that resource�s queue� The pro cess obtains the resource when its index reac hes the fron t of that resource�s queue� When a pro cess exits C� it returns all of its resources b y remo ving its index from their queues� Let us assume that is the maxim um n um b er k of pro cesses that require an y single resource� What is the time complexit y of the algorithm� � � DS I I L���� Philippas Tsigas

Recommend


More recommend