Changes for page Deadlock Prevention
Last modified by chrisby on 2023/11/28 19:17
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -1,11 +1,11 @@ 1 1 Deadlocks can only occur if all four specific conditions are met. Therefore, strategies to prevent deadlocks focus on negating one of these conditions. 2 2 3 -| ------------------------ -----------| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|4 -| 5 -| hared betweenthreadsand there arefewerresources than threads.suchasAtomicInteger. 2) Increase the number of resources until itis greaterthanor equal to the number of competing threads. 3) Check if eachrequired resource is accessible beforestarting the task. |6 -| has acquireda resource, it will not releaseit until it has acquired all the other resources itneeds and has completed its work.ga resource, check its availability. If a resource isunavailable, releaseallresourcesand start over.manages to reserve allthe resourcesit needs. 2) Livelock: The thread gets tangled up. →These two approachesare always applicable,but inefficientbecausetheycause bad performance.7 -| NoPreemption|Athreadisunabletostealaresourcesreservedbyanotherthread.|Athreadisallowedtoaskanotherthreadtoreleaseallofitsresources(includingtherequiredone)andstartingfromanew.Thisapproachissimilartothe'Lock&Wait'solutionbuthasabetterperformance.||8 -| CircularWaiting/DeadlyEmbrace|Whentwoormorethreadsrequirearesourcewhichisalreadyreservedbyanotherofthesethreads.Example:ThreadT1hasresourceR1andwaitsforR2tobereleased.ThreadT2hasresourceR2andwaitsforR1tobereleased.|Allthreadsreserveallresourcesinathesameorder.|1)Theorderofreservationdoesn'tnecessarilyhavetobethesameastheorderofusage.Thisleadstoinefficiencieslikereservingaresourceatthebeginningwhichisjustrequiredattheendofthetask.2)Unnecessarilylonglockedresources.3)Ordercannotalwaysbespecified.|3 +| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | 4 +| **Condition** | **Description** | **Solutions** | **Dangers** | 5 +| Mutual Exclusion / Mutex | When resources can't be used by mutual thread and there are less resources than threads. | 1) Use concurrently accessible resources like AtomicInteger. 2) Increase the number of resources until its greater or equal to the number of competing threads. 3 ) Check if every required resource is accessible before the task starts. | | 6 +| Lock & Wait | Once a thread acquires a resource, it will not release the resource until it has acquired all of the other resources it requires and has completed its work. | Before reservation of a resource, check its accessibility. If a resource is not accessible, release every resource and start from anew. | 1) Starvation: A thread never achieves to reserve all required resources. 2) Livelock: Thread gets tangled up. →These two approach are always applicable but inefficient as it causes a bad performance. | 7 +| | | | | 8 +| | | | | 9 9 10 10 #### Lock & Wait 11 11