操作系统-精髓与设计原理英文ppt-Chapter06

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1Concurrency:DeadlockandStarvationChapter62Deadlock•Eachprocessinaprocessgroupiswaitingforsomeresourceoccupiedbyanotherprocessofthesamegroup,sothateveryprocessofthegroupisinstarvation•Permanentblockingofasetofprocessesthateithercompeteforsystemresourcesorcommunicatewitheachother•Noefficientsolution•Involveconflictingneedsforresourcesbytwoormoreprocesses3P1P2P3P44ProcessPProcessQ…………GetAGetB…………GetBGetA…………ReleaseAReleaseB…………ReleaseBReleaseA…………5ProcessPProcessQ…………GetAGetB…………ReleaseAGetA…………GetBReleaseB…………ReleaseBReleaseA…………6ReusableResources•Usedbyonlyoneprocessatatimeandnotdepletedbythatuse•Processesobtainresourcesthattheylaterreleaseforreusebyotherprocesses•Processors,I/Ochannels,mainandsecondarymemory,devices,anddatastructuressuchasfiles,databases,andsemaphores•Deadlockoccursifeachprocessholdsoneresourceandrequeststheother7ExampleofDeadlockDeadlockwouldbehappenedifExecutingsequenceisp0p1q0q1p2q28AnotherExampleofDeadlock•Spaceisavailableforallocationof200Kbytes,andthefollowingsequenceofeventsoccur•DeadlockoccursifbothprocessesprogresstotheirsecondrequestP1......Request80Kbytes;Request60Kbytes;P2......Request70Kbytes;Request80Kbytes;9ConsumableResources•Created(produced)anddestroyed(consumed)•Interrupts,signals,messages,andinformationinI/Obuffers•DeadlockmayoccurifaReceivemessageisblocking•Maytakeararecombinationofeventstocausedeadlock10ExampleofDeadlock•DeadlockoccursifreceivesareblockingP1......Receive(P2);Send(P2,M1);P2......Receive(P1);Send(P1,M2);11ResourceAllocationGraphs•Directedgraphthatdepictsastateofthesystemofresourcesandprocesses12ResourceAllocationGraphs13ConditionsforDeadlock•Mutualexclusion–Onlyoneprocessmayusearesourceatatime•Hold-and-wait–Aprocessmayholdallocatedresourceswhileawaitingassignmentofothers•Nopreemption–Noresourcecanbeforciblyremovedfromaprocessholdingit14ConditionsforDeadlock•Circularwait–aclosedchainofprocessesexists,suchthateachprocessholdsatleastoneresourceneededbythenextprocessinthechain–consequenceofthefirstthreeconditions1516ConditionsforDeadlock•MutualExclusion•Nopreemption•Holdandwait•Circularwait•Eachofthesefourconditionsisnecessary,andfourconditionstakentogetherconstitutenecessaryandsufficientconditionsfordeadlock17DeadlockPrevention•Designasysteminsuchawaythatthepossibilityofdeadlockisexcluded–MutualExclusion•Impracticable,operatingsystemsmustsupportthefeature–HoldandWait•Requireaprocessrequestallofitsrequiredresourcesatonetime•blocktheprocessuntilallrequestscanbegrantedsimultaneously•processmaybeheldupforalongtimewaitingforallitsrequests•resourcesallocatedtoaprocessmayremainunusedforalongtime.Theseresourcescouldbeusedbyotherprocesses18DeadlockPrevention•NoPreemption–Ifaprocessisdeniedafurtherrequest,itmustreleaseresourceandrequestagain–Ifaprocessrequestsaresourcethatiscurrentlyheldbyanotherprocess,OSmaypreemptthisprocesstorequireitreleasesitsresources–Practicalonlywhenthestatecanbeeasilysavedandrestoredlater,suchasprocessors•CircularWait–Definealinearorderingofresourcetypessuchthatoncearesourceisobtained,onlythoseresourceshigherinthelistcanbeobtained–Maydenyresourcesunnecessarily19DeadlockAvoidance•Adecisionismadedynamicallywhetherthecurrentresourceallocationrequestwill,ifgranted,potentiallyleadtoadeadlock•Requiresknowledgeoffutureprocessrequest20TwoApproachestoDeadlockAvoidance•Donotstartaprocessifitsdemandsmightleadtodeadlock•Resourceallocationdenial:Donotgrantanincrementalresourcerequesttoaprocessifthisallocationmightleadtodeadlock21ResourceAllocationDenial•ReferredtoasBanker’sAlgorithm•Stateofthesystemisthecurrentallocationofresourcestoprocess•Safestateisoneinwhichthereisatleastoneorderinwhichalltheprocessescanberuntocompletionwithoutresultinginadeadlock•Unsafestateisastatethatisnotsafe22DeterminationofaSafeStateInitialStateFigure6.7DeterminationofasafeState23DeterminationofaSafeStateP2RunstoCompletionFigure6.7DeterminationofasafeState24DeterminationofaSafeStateP1RunstoCompletionFigure6.7DeterminationofasafeState25DeterminationofaSafeStateP3RunstoCompletionFigure6.7DeterminationofasafeState26DeterminationofanUnsafeStateFigure6.8DeterminationofanUnsafeState27DeterminationofanUnsafeStateFigure6.8DeterminationofanUnsafeStateP1request:10128DeadlockAvoidanceLogic-Banker’sAlgorithm29DeadlockAvoidanceLogic-Banker’sAlgorithm30DeadlockAvoidance•ProsandCons–Norollbackandnopreemption–Lessrestrictivethandeadlockprevention–Maximumresourcerequirementmustbestatedinadvance–Processesunderconsiderationmustbeindependent;nosynchronizationrequirements–Theremustbeafixednumberofresourcestobeallocated–Noprocessmayexitwhileholdingresources31DeadlockDetection•Donotlimitresourcesaccessorrestrictprocessactions•Requestedresourcesaregrantedtoprocesseswheneverpossible•SomedeadlockdetectionalgorithmperformedperiodicallybyOStodetectthecircularwaitcondition•Oncedeadlockhasbeendetected,somerecoverystrategyistaken32DeadlockDetection•Detectionalgorithmdatastructure–Allocationmatrix,Resourcevector,andAvailablevector–RequestmatrixQisdefinedsuchthatqijrepresentstheamountofresourcesoftypejrequest

1 / 53
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功