Dining Philosopher's Problem

YashMittal3 10,198 views 11 slides Dec 20, 2015
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

A presentation on the Dining Philosopher's Problem, explaining the problem, issues while solving the problem and solutions to the problem. The presentation then takes the user through the Requirement Engineering for the problem via its 4 phases, including, Requirement Discovery, Analysis, Valida...


Slide Content

DINING PHILOSOPHER’S
PROBLEM
© Yash Mittal 1

THE PROBLEM
TheScenario
-5silentphilosopherssitataroundtablewith5bowlsof
spaghetti
-Aforkisplacedbetweeneachpairofadjacentphilosophers
-EatingisNOTlimitedbyamountofspaghettileft:infinite
supplyassumed
TheRules
-Eachphilosophermust‘alternately’thinkandeat
-Aphilosophercanonlyeatspaghettiwhenhehasbothleft
andrightforks
-Eachforkcanbeheldbyonly1philosopher
-Aftereating,heneedstoputdownbothforkssothey
becomeavailabletoothers
-Aphilosophercangrabtheforkonleftorrightasthey
becomeavailable
→Hecan’tstarteatinguntilhehasbothofthem
© Yash Mittal 2

PROBLEMS
How to design a Concurrent Algorithm such that each philosopher won’t starve, i.e., he can
forever continue to alternate between eating and thinking assuming that any philosopher
cannot know when others may want to eat or think.
The problem was designed to illustrate the challenges of avoiding Deadlock –a system state in
which no progress is possible.
Resource Starvation
-A problem encountered in multitasking where a process is perpetually denied necessary
resources. Without them the process can never finish its task,
-Resource Starvation might occur independently if a particular philosopher is unable to acquire
both forks because of a timing problem.
Mutual Exclusion
-Ensuring that no 2 concurrent processes are in their critical section at the same time.
-A basic requirement in Concurrency Control to prevent race conditions.
© Yash Mittal 3

SOLUTIONS
ResourceHierarchySolution
-Assignsapartialordertotheresources(forks)
-Allresourceswillberequestedinorder&no2resourcesunrelatedbyorder
willeverbeusedbyasingleunitofworkatthesametime.
-Resourcesarenumbered1-5andeachphilosopherwillalwayspickupthe
lower-numberedforkfirstandthenthehigher-numberedfork.
-If4of5philosopherssimultaneouslypickuptheir‘lowfork’,only1‘highfork’
willremainonthetable.Sothe5thphilosopherwillNOTbeabletopickup
anyfork.
→Also,only1philosopherwillhaveaccesstothe‘highfork’hewillbe
abletoeatusing2forks
-Notalwayspracticaliflistofrequiredresourcesisnotcompletelyknownin
advance.
© Yash Mittal 4

Arbitrator Solution
-Guaranteethataphilosophercanpickuponly2solutionsbyintroducingan
arbitrator,Ex:waiter.
→Inordertopickuptheforks,aphilosophermustaskwaiter’s
permission
→Waitergivespermissiontoonly1philosopheratatimeuntilhehas
pickedupbothhisforks
→Puttingdownaforkisalwaysallowed.
-Waiterisimplementedasamutex-aprogramobjectthatallowsmultiple
programthreadstosharethesameresource,suchasfileaccess,butnot
simultaneously.
© Yash Mittal 5

Requirement Engineering
Requirements are of 2 types:
i.User
ii.System
a.Functional Requirements
b.Non-Functional Requirements
c.Domain Requirements
Process of identification of requirementsis called Requirement Engineering.
Four phases
1.Requirement Discovery
2.Requirement Analysis
3.Requirement Validation
4.Requirement Management
© Yash Mittal 6

Requirement Discovery Phase
Scenario–basedModelling
UseCaseDiagram
–Actor :Philosophers
–UseCases :Thinking,Eating,AcquiringResources(forks)
CompositionofScenario[EATING]
–Pre-Condition:Resources(forks)available
–NormalFlow:Philosopher2forksavailableEatingspaghetti
FinishedPutdownforksThinking
–AbnormalFlow:Philosopheriseating
Anotherphilosopheravailsresources(Deadlock)
–OtherActivity:ResourceisnotavailablePhilosopherthinks
–Post-Condition:Freetheresources(forksareavailable)
© Yash Mittal 7

Requirement Analysis Phase
3 Types of Modelling
i.Class/Object Models
ii.Flow Oriented Models
iii.Behaviour Models
Flow Oriented Models –Data Flow Diagrams
DFD Level 0
© Yash Mittal 8

DFD Level 1
© Yash Mittal 9

Behaviour Modelling
State Diagram
Sequence Diagram
© Yash Mittal 10

THANK YOU
© Yash Mittal 11