SlideShare a Scribd company logo
CS 704DAdvanced Operating SystemDebasis Das
Tools for Implementationof Semaphores #3Compare & Swap InstructionsHelps consistent update of global variableImplementationCompare Oldreg, GlobvarSet condition codesIf (Oldreg=Globvar) Then Globvar Newreg                                       Else OldregGlobvarMIT    CS704D Advanced OS           Class of 20112
Queuing Implementationof SemaphoreMIT    CS704D Advanced OS           Class of 20113SemaphorePz…..PyPxWait(s):  If not (s>0) then suspend caller at s                 else s:= s+1Signal (s):  if queue is not empty (at least one process is waiting)                     then  resume process from the queue at s                     else s:=s+1
Overview of Classical Synchronization problemsProducers and consumersWith unbounded buffersWith bounded buffersReaders and writersMIT    CS704D Advanced OS           Class of 20114
Producers & ConsumersOne class of processes produce data itemsThe other class consumes/uses this dataThey may have different rates and thus cause synchronization problemsSynchronizations required so that producers & consumers are able to operate concurrentlySuch that items produced are consumed in the same orderDisplay, keyboard was an exampleProcesses may be a combination of both producer and consumerMIT    CS704D Advanced OS           Class of 20115
Producers & Consumers(unbounded buffer case)If we can prevent a process trying to consume something before at least one item is available, sync is achievedA semaphore “Producer” can take care of thatWe assume buffer manipulation does not cause problemsThis is not really a valid assumption in multiple producer, consumer situationsMIT    CS704D Advanced OS           Class of 20116
Unbounded Buffer CaseA mutex controlling buffer access can manage the situation wellHow the mutex is used exactly can have unintended implicationsIf the waiting on “producer” is placed within the critical section, there can be deadlocksInitially, for example, when nothing has been produced and a consumer is scheduled, the consumer will get through to the critical sectionThen wait forever on Producer as a producer process cannot get into the critical sectionMIT    CS704D Advanced OS           Class of 20117
Producers & Consumers(bounded buffer case)Additional management issues are that the buffers are to be controlledProducers should not produce when buffer is full, it will overwrite some existing dataConsumers, similarly will consume wrong data if buffer is emptyThese conditions have to be controlledMIT    CS704D Advanced OS           Class of 20118
Unbounded case Icount=produced-consumedNecessary that icount cannot be  less than zero and more than the capacityThenCondition mayproduce : icount < capacity as also  mayconsume: icount>0MIT    CS704D Advanced OS           Class of 20119
Readers & WritersReaders and consumers are processes that operate against some common data structureReaders are pure readers, only reads parts or all of the data structureWriters write and thus modify the data structure. It can also read the structure or parts of itReaders thus can safely get interleaved with other readersBut writes cannot be interleaved with other readers or writersMIT    CS704D Advanced OS           Class of 201110
The sync ProblemGiven a universe of readers that read a common data structure, and a universe of writers that modify the same common data structureA sync mechanism needs to be devised to control readers and writers to ensure consistency of common data  and maintain as high  a concurrency as possibleMIT    CS704D Advanced OS           Class of 201111
Example SynchronizationHigh concurrencyAllows high number of readers to access common resourceWriter waits for the wait semaphoreReader process makes it possible for multiple readers to workReadercount really tracks if even one reader is activeNext round, the writer gets  turn only when all readers finished reading, that may be unfairMIT    CS704D Advanced OS           Class of 201112
Suggested Modifications(according to C A R Hoare)A reader should not start if there’s a writer waiting, preventing starvation for writersAll readers waiting at the end of a write cycle should be given priority, preventing starvation of  readersMIT    CS704D Advanced OS           Class of 201113
Inter-process Communication& SynchronizationMIT    CS704D Advanced OS           Class of 201114
Semaphore ProblemsSync and system integration depend on strict following of the discipline and implementation. Forgetting of either of wait and signal mechanism, reversing or going around it  will cause problems in the systemSemaphores control access to shared resources but cannot prevent misuse of the same by some process granted access to these global variables.MIT    CS704D Advanced OS           Class of 201115
Critical Regions & Conditional critical RegionsStrong typing and compile time checks can prevent some of the problemsFor example var mutex : shared T; and critical section as follows region mutex doThe compiler can ensure wait and signals are introduced properly, no probability of errorsMIT    CS704D Advanced OS           Class of 201116
Why condionality requiredSometimes a process getting access to the CS may still need some condition to be fulfilled and thus block other processing entering the CSConditional CS construct can prevent such problemsMIT    CS704D Advanced OS           Class of 201117
Conditional Critical Regionvar mutex: shared T;begin region  v dobeginawait conditionend;End;Special queue is maintained, allowed only when the condition is metMIT    CS704D Advanced OS           Class of 201118
MonitorMIT    CS704D Advanced OS           Class of 201119Enforce concurrencyProcessesProcessesAccess, modify shared variable(s)
Monitors-Plus MinusCan regulate a group of related resources tooIf this is too many, the serialization  overhead could be too muchSame things can be done at kernel levelSerialization overheads will cause problems very quickly as kernel controls all kinds of resourcesWriting, building, debugging such monolithic structures could be problematicMonitors can create a  deadlockMonitor disciplines may restrict application programmersMIT    CS704D Advanced OS           Class of 201120
MessagesA collection of data, execution commands, sometimes even codeInterchanged between sending and receiving processesMIT    CS704D Advanced OS           Class of 201121Sender idReceiver idLengthHeaderType……Message body
Issues in Message ImplementationNamingDirect, indirect  (mailbox)CopyingCopy message, pass  pointerSynchronous/asynchronousSynchronous can be blocking, asynchronous can cause runaway,  indefinite postponementLengthFixed or variable length  (overhead vs. flexibility)MIT    CS704D Advanced OS           Class of 201122
Inter-process Communication & sync with MessagesAssume buffered message, infinite channel capacity, indirect naming (via mailboxes)Sender  send s the message & continues, receiver will be suspended if no messageSync through semaphore like operation of messages. Signal send a message to waiting on semaphore, wait is just waiting to receive a messageSync also can be through messagesExample; producer waits for a message through mayproduce mailbox, a consumer  gets a  mayconsumeMIT    CS704D Advanced OS           Class of 201123
Interrupt Signaling via MessageA message (signal) can initiate a set of waiting interrupt service processesInterrupt service need not be treated differently from other processesHardware interrupts that need guaranteed response time, may be a problemAll software interrupts can be handled this wayMIT    CS704D Advanced OS           Class of 201124
DeadlocksA deadlock is a situation where processes are permanently blocked as a result of each process having acquired a subset of  the resources needed for its completion and waiting for the release of the remaining resources held by others in the same group- thus making it impossible for any of the processes to proceed.MIT    CS704D Advanced OS           Class of 201125
Necessary ConditionsMutual exclusion. Shared resources are used exclusively by at most one process at a time.Hold & Wait. Resources already allocated are held by the process and waits for the balance to be acquiredNo preemption.  Resources are released only when given up by the ownerCircular waiting. Each process hold one or more resources being requested by the next process in the chainMIT    CS704D Advanced OS           Class of 201126
Reusable & Consumable ResourcesReusable. Resources that can be safely used by one process at any time.It is either available or allocated to a processIt can only be relinquished by the ownerSingle resource multiple instances, multiple resources of single instanceConsumable resources. Once consumed, these do not exist any more; example messages. Deadlocks can happen, such as a receiver waiting for a message. OS must intervene to break such deadlocks.MIT    CS704D Advanced OS           Class of 201127
Deadlock Prevention-1Hold-an-wait condition can be resolved by forcing release of all other held resources when the process requests for a resource that is not available.Request all resources prior to executionAsks for resources as needed but relinquishes resources held by it when a requested resource is not availableOverestimation of resources, holding on to resources longer than necessaryReduces concurrency, resources are underutilizedMIT    CS704D Advanced OS           Class of 201128
Deadlock Prevention-2No-preemptionissue can obviously be solved by allowing preemptionOS will need to save the state of the processFor some resources the preemption may not be a problem, like CPU and memory pages but resources like files cannot be safely preempted without corrupting the systemApply such policies only when the benefits of deadlock prevention is more than the cost of save & restore of state of some resourcesMIT    CS704D Advanced OS           Class of 201129
Deadlock Prevention-3Circular wait.  Request resources of a higher class only after the resources from a lower class has been acquired successfully. All requests in a given class must be acquired through a single request.The prescribed ordering can be checked at compile time, avoiding run time problemsDisadvantagesAll resources must be acquired up frontLower degree of concurrency and lower utilization of resourcesMIT    CS704D Advanced OS           Class of 201130
Deadlock AvoidanceGrant resources only if the request is not likely to cause deadlocksA resource allocator must examine the implicationsAll processes must proclaim maximum needWhen requested, the resource allocator must check if the other executing processes can safely complete (they have resource allocation pending) . If not the process should wait.MIT    CS704D Advanced OS           Class of 201131
Deadlock detection & RecoveryIf the general resource  graph has a cycle or a knot then deadlock existsRollback or restarting can be optionsState needs to be knownSome systems have check pointing or journaling system, one could use thatMIT    CS704D Advanced OS           Class of 201132
Combined ApproachTypical classes of devicesSwap areaJob resources & assignable devicesMain memory (by page, segment etc.)Internal resources such as I/O channels, buffer pool etc.Deadlock prevention between the main classes, deadlock handling within each class is usedMIT    CS704D Advanced OS           Class of 201133
Combined PoliciesSwap space: advance booking of all swap space. Dead lock detection is not possibleJob resources: pre-claiming of resources, Resource ordering also is possible. Detection combined with recovery is undesirable, as can have repercussions on file resourcesMain memory : preemption is used but not avoidance as that has run time overheads and resource underutilizationInternal system resources : avoidance or detection will have performance penalties. Prevention by means of resource ordering is typically doneMIT    CS704D Advanced OS           Class of 201134

More Related Content

DOCX
Operating System Process Synchronization
PDF
Operating Systems 1 (8/12) - Concurrency
PPT
Process Synchronization And Deadlocks
PPTX
It 802 d_Mobile Communications_part 2
PPTX
Cs 704 D Aos Distr File System
PPTX
The Life Of Taylor Stanley
PPSX
David Murr’S Technical Writer Demo
PPTX
Cs 704 d set2
Operating System Process Synchronization
Operating Systems 1 (8/12) - Concurrency
Process Synchronization And Deadlocks
It 802 d_Mobile Communications_part 2
Cs 704 D Aos Distr File System
The Life Of Taylor Stanley
David Murr’S Technical Writer Demo
Cs 704 d set2

Viewers also liked (14)

PPTX
It802 d mobilecommunicationspart4
PPTX
Cs704 d distributedschedulingetc.
PPTX
It802 d mobilecommunicationspart3
PPTX
The Life Of Taylor Stanley
PPT
Management control systems jsb 606 part4
PPTX
Cs 704 d rpc
PDF
Evolution of Social Media Marketing - Tom Edwards
PPTX
Management control systems jsb 606 part1
PPTX
IoT: An Introduction and Getting Started Session
PPTX
Ei502 microprocessors & micrtocontrollers part3hardwareinterfacing
PPTX
Microprocessors & microcontrollers- The design Context
PPTX
Trends in education management
PPTX
Ei502microprocessorsmicrtocontrollerspart4 8051 Microcontroller
PPT
Advanced Operating System- Introduction
It802 d mobilecommunicationspart4
Cs704 d distributedschedulingetc.
It802 d mobilecommunicationspart3
The Life Of Taylor Stanley
Management control systems jsb 606 part4
Cs 704 d rpc
Evolution of Social Media Marketing - Tom Edwards
Management control systems jsb 606 part1
IoT: An Introduction and Getting Started Session
Ei502 microprocessors & micrtocontrollers part3hardwareinterfacing
Microprocessors & microcontrollers- The design Context
Trends in education management
Ei502microprocessorsmicrtocontrollerspart4 8051 Microcontroller
Advanced Operating System- Introduction
Ad

Similar to Cs 704 d set3 (20)

PPTX
Chapter05 new
PPTX
Chapter 6 Concurrency: Deadlock and Starvation
PPTX
Cs 704 d set4distributedcomputing-1funda
PPT
Processes, Threads and Scheduler
PPT
Scalable Apache for Beginners
PPT
MODERN OPERATING SYSTEMS Chapter02 Processes and Threads.ppt
PDF
Foundational Design Patterns for Multi-Purpose Applications
PDF
Operating system Interview Questions
PPTX
Tef con2016 (1)
PPTX
Concurrency: Mutual Exclusion and Synchronization
PPTX
LM9 - OPERATIONS, SCHEDULING, Inter process xommuncation
PDF
Lecture 5- Process Synchonization_revised.pdf
PPTX
Demystifying the use of circuit breakers with MuleSoft
DOCX
Process synchronization
PPTX
Debugging Microservices - QCON 2017
PDF
Beyond the RTOS: A Better Way to Design Real-Time Embedded Software
DOCX
Operating System- INTERPROCESS COMMUNICATION.docx
PDF
Dot NET Interview Questions PDF By ScholarHat
PPT
Monitor(karthika)
PDF
Data Virtualization Deployments: How to Manage Very Large Deployments
Chapter05 new
Chapter 6 Concurrency: Deadlock and Starvation
Cs 704 d set4distributedcomputing-1funda
Processes, Threads and Scheduler
Scalable Apache for Beginners
MODERN OPERATING SYSTEMS Chapter02 Processes and Threads.ppt
Foundational Design Patterns for Multi-Purpose Applications
Operating system Interview Questions
Tef con2016 (1)
Concurrency: Mutual Exclusion and Synchronization
LM9 - OPERATIONS, SCHEDULING, Inter process xommuncation
Lecture 5- Process Synchonization_revised.pdf
Demystifying the use of circuit breakers with MuleSoft
Process synchronization
Debugging Microservices - QCON 2017
Beyond the RTOS: A Better Way to Design Real-Time Embedded Software
Operating System- INTERPROCESS COMMUNICATION.docx
Dot NET Interview Questions PDF By ScholarHat
Monitor(karthika)
Data Virtualization Deployments: How to Manage Very Large Deployments
Ad

More from Debasis Das (15)

PPTX
Developing robust &amp; enterprise io t applications
PPTX
Development eco-system in free-source for io t
PPT
Management control systems jsb 606 part3
PPT
Management control systems jsb 606 part2
PPT
Computers for management jsb 1072003 ver
PPTX
Ei502microprocessorsmicrtocontrollerspart5 sixteen bit8086 1
PPTX
Ei502 microprocessors & micrtocontrollers part 2(instructionset)
PPTX
Ei502 microprocessors & micrtocontrollers part 1
PPTX
It 802 d_Mobile Communications_part 2
PPT
It 802 d_mobile_communicationsSomeHistory
PPTX
It 802 d_intro&wlan
PPTX
It 802 d_intro&wlan
PPTX
Cs704 d distributedmutualexcclusion&memory
PPTX
Cs 704 d aos-resource&processmanagement
PPTX
Cs 704 d dce ipc-msgpassing
Developing robust &amp; enterprise io t applications
Development eco-system in free-source for io t
Management control systems jsb 606 part3
Management control systems jsb 606 part2
Computers for management jsb 1072003 ver
Ei502microprocessorsmicrtocontrollerspart5 sixteen bit8086 1
Ei502 microprocessors & micrtocontrollers part 2(instructionset)
Ei502 microprocessors & micrtocontrollers part 1
It 802 d_Mobile Communications_part 2
It 802 d_mobile_communicationsSomeHistory
It 802 d_intro&wlan
It 802 d_intro&wlan
Cs704 d distributedmutualexcclusion&memory
Cs 704 d aos-resource&processmanagement
Cs 704 d dce ipc-msgpassing

Recently uploaded (20)

PDF
TR - Agricultural Crops Production NC III.pdf
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Insiders guide to clinical Medicine.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Pharma ospi slides which help in ospi learning
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
VCE English Exam - Section C Student Revision Booklet
TR - Agricultural Crops Production NC III.pdf
01-Introduction-to-Information-Management.pdf
Microbial diseases, their pathogenesis and prophylaxis
Supply Chain Operations Speaking Notes -ICLT Program
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Insiders guide to clinical Medicine.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Microbial disease of the cardiovascular and lymphatic systems
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Renaissance Architecture: A Journey from Faith to Humanism
GDM (1) (1).pptx small presentation for students
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Abdominal Access Techniques with Prof. Dr. R K Mishra
O5-L3 Freight Transport Ops (International) V1.pdf
Pharma ospi slides which help in ospi learning
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
VCE English Exam - Section C Student Revision Booklet

Cs 704 d set3

  • 1. CS 704DAdvanced Operating SystemDebasis Das
  • 2. Tools for Implementationof Semaphores #3Compare & Swap InstructionsHelps consistent update of global variableImplementationCompare Oldreg, GlobvarSet condition codesIf (Oldreg=Globvar) Then Globvar Newreg Else OldregGlobvarMIT CS704D Advanced OS Class of 20112
  • 3. Queuing Implementationof SemaphoreMIT CS704D Advanced OS Class of 20113SemaphorePz…..PyPxWait(s): If not (s>0) then suspend caller at s else s:= s+1Signal (s): if queue is not empty (at least one process is waiting) then resume process from the queue at s else s:=s+1
  • 4. Overview of Classical Synchronization problemsProducers and consumersWith unbounded buffersWith bounded buffersReaders and writersMIT CS704D Advanced OS Class of 20114
  • 5. Producers & ConsumersOne class of processes produce data itemsThe other class consumes/uses this dataThey may have different rates and thus cause synchronization problemsSynchronizations required so that producers & consumers are able to operate concurrentlySuch that items produced are consumed in the same orderDisplay, keyboard was an exampleProcesses may be a combination of both producer and consumerMIT CS704D Advanced OS Class of 20115
  • 6. Producers & Consumers(unbounded buffer case)If we can prevent a process trying to consume something before at least one item is available, sync is achievedA semaphore “Producer” can take care of thatWe assume buffer manipulation does not cause problemsThis is not really a valid assumption in multiple producer, consumer situationsMIT CS704D Advanced OS Class of 20116
  • 7. Unbounded Buffer CaseA mutex controlling buffer access can manage the situation wellHow the mutex is used exactly can have unintended implicationsIf the waiting on “producer” is placed within the critical section, there can be deadlocksInitially, for example, when nothing has been produced and a consumer is scheduled, the consumer will get through to the critical sectionThen wait forever on Producer as a producer process cannot get into the critical sectionMIT CS704D Advanced OS Class of 20117
  • 8. Producers & Consumers(bounded buffer case)Additional management issues are that the buffers are to be controlledProducers should not produce when buffer is full, it will overwrite some existing dataConsumers, similarly will consume wrong data if buffer is emptyThese conditions have to be controlledMIT CS704D Advanced OS Class of 20118
  • 9. Unbounded case Icount=produced-consumedNecessary that icount cannot be less than zero and more than the capacityThenCondition mayproduce : icount < capacity as also mayconsume: icount>0MIT CS704D Advanced OS Class of 20119
  • 10. Readers & WritersReaders and consumers are processes that operate against some common data structureReaders are pure readers, only reads parts or all of the data structureWriters write and thus modify the data structure. It can also read the structure or parts of itReaders thus can safely get interleaved with other readersBut writes cannot be interleaved with other readers or writersMIT CS704D Advanced OS Class of 201110
  • 11. The sync ProblemGiven a universe of readers that read a common data structure, and a universe of writers that modify the same common data structureA sync mechanism needs to be devised to control readers and writers to ensure consistency of common data and maintain as high a concurrency as possibleMIT CS704D Advanced OS Class of 201111
  • 12. Example SynchronizationHigh concurrencyAllows high number of readers to access common resourceWriter waits for the wait semaphoreReader process makes it possible for multiple readers to workReadercount really tracks if even one reader is activeNext round, the writer gets turn only when all readers finished reading, that may be unfairMIT CS704D Advanced OS Class of 201112
  • 13. Suggested Modifications(according to C A R Hoare)A reader should not start if there’s a writer waiting, preventing starvation for writersAll readers waiting at the end of a write cycle should be given priority, preventing starvation of readersMIT CS704D Advanced OS Class of 201113
  • 14. Inter-process Communication& SynchronizationMIT CS704D Advanced OS Class of 201114
  • 15. Semaphore ProblemsSync and system integration depend on strict following of the discipline and implementation. Forgetting of either of wait and signal mechanism, reversing or going around it will cause problems in the systemSemaphores control access to shared resources but cannot prevent misuse of the same by some process granted access to these global variables.MIT CS704D Advanced OS Class of 201115
  • 16. Critical Regions & Conditional critical RegionsStrong typing and compile time checks can prevent some of the problemsFor example var mutex : shared T; and critical section as follows region mutex doThe compiler can ensure wait and signals are introduced properly, no probability of errorsMIT CS704D Advanced OS Class of 201116
  • 17. Why condionality requiredSometimes a process getting access to the CS may still need some condition to be fulfilled and thus block other processing entering the CSConditional CS construct can prevent such problemsMIT CS704D Advanced OS Class of 201117
  • 18. Conditional Critical Regionvar mutex: shared T;begin region v dobeginawait conditionend;End;Special queue is maintained, allowed only when the condition is metMIT CS704D Advanced OS Class of 201118
  • 19. MonitorMIT CS704D Advanced OS Class of 201119Enforce concurrencyProcessesProcessesAccess, modify shared variable(s)
  • 20. Monitors-Plus MinusCan regulate a group of related resources tooIf this is too many, the serialization overhead could be too muchSame things can be done at kernel levelSerialization overheads will cause problems very quickly as kernel controls all kinds of resourcesWriting, building, debugging such monolithic structures could be problematicMonitors can create a deadlockMonitor disciplines may restrict application programmersMIT CS704D Advanced OS Class of 201120
  • 21. MessagesA collection of data, execution commands, sometimes even codeInterchanged between sending and receiving processesMIT CS704D Advanced OS Class of 201121Sender idReceiver idLengthHeaderType……Message body
  • 22. Issues in Message ImplementationNamingDirect, indirect (mailbox)CopyingCopy message, pass pointerSynchronous/asynchronousSynchronous can be blocking, asynchronous can cause runaway, indefinite postponementLengthFixed or variable length (overhead vs. flexibility)MIT CS704D Advanced OS Class of 201122
  • 23. Inter-process Communication & sync with MessagesAssume buffered message, infinite channel capacity, indirect naming (via mailboxes)Sender send s the message & continues, receiver will be suspended if no messageSync through semaphore like operation of messages. Signal send a message to waiting on semaphore, wait is just waiting to receive a messageSync also can be through messagesExample; producer waits for a message through mayproduce mailbox, a consumer gets a mayconsumeMIT CS704D Advanced OS Class of 201123
  • 24. Interrupt Signaling via MessageA message (signal) can initiate a set of waiting interrupt service processesInterrupt service need not be treated differently from other processesHardware interrupts that need guaranteed response time, may be a problemAll software interrupts can be handled this wayMIT CS704D Advanced OS Class of 201124
  • 25. DeadlocksA deadlock is a situation where processes are permanently blocked as a result of each process having acquired a subset of the resources needed for its completion and waiting for the release of the remaining resources held by others in the same group- thus making it impossible for any of the processes to proceed.MIT CS704D Advanced OS Class of 201125
  • 26. Necessary ConditionsMutual exclusion. Shared resources are used exclusively by at most one process at a time.Hold & Wait. Resources already allocated are held by the process and waits for the balance to be acquiredNo preemption. Resources are released only when given up by the ownerCircular waiting. Each process hold one or more resources being requested by the next process in the chainMIT CS704D Advanced OS Class of 201126
  • 27. Reusable & Consumable ResourcesReusable. Resources that can be safely used by one process at any time.It is either available or allocated to a processIt can only be relinquished by the ownerSingle resource multiple instances, multiple resources of single instanceConsumable resources. Once consumed, these do not exist any more; example messages. Deadlocks can happen, such as a receiver waiting for a message. OS must intervene to break such deadlocks.MIT CS704D Advanced OS Class of 201127
  • 28. Deadlock Prevention-1Hold-an-wait condition can be resolved by forcing release of all other held resources when the process requests for a resource that is not available.Request all resources prior to executionAsks for resources as needed but relinquishes resources held by it when a requested resource is not availableOverestimation of resources, holding on to resources longer than necessaryReduces concurrency, resources are underutilizedMIT CS704D Advanced OS Class of 201128
  • 29. Deadlock Prevention-2No-preemptionissue can obviously be solved by allowing preemptionOS will need to save the state of the processFor some resources the preemption may not be a problem, like CPU and memory pages but resources like files cannot be safely preempted without corrupting the systemApply such policies only when the benefits of deadlock prevention is more than the cost of save & restore of state of some resourcesMIT CS704D Advanced OS Class of 201129
  • 30. Deadlock Prevention-3Circular wait. Request resources of a higher class only after the resources from a lower class has been acquired successfully. All requests in a given class must be acquired through a single request.The prescribed ordering can be checked at compile time, avoiding run time problemsDisadvantagesAll resources must be acquired up frontLower degree of concurrency and lower utilization of resourcesMIT CS704D Advanced OS Class of 201130
  • 31. Deadlock AvoidanceGrant resources only if the request is not likely to cause deadlocksA resource allocator must examine the implicationsAll processes must proclaim maximum needWhen requested, the resource allocator must check if the other executing processes can safely complete (they have resource allocation pending) . If not the process should wait.MIT CS704D Advanced OS Class of 201131
  • 32. Deadlock detection & RecoveryIf the general resource graph has a cycle or a knot then deadlock existsRollback or restarting can be optionsState needs to be knownSome systems have check pointing or journaling system, one could use thatMIT CS704D Advanced OS Class of 201132
  • 33. Combined ApproachTypical classes of devicesSwap areaJob resources & assignable devicesMain memory (by page, segment etc.)Internal resources such as I/O channels, buffer pool etc.Deadlock prevention between the main classes, deadlock handling within each class is usedMIT CS704D Advanced OS Class of 201133
  • 34. Combined PoliciesSwap space: advance booking of all swap space. Dead lock detection is not possibleJob resources: pre-claiming of resources, Resource ordering also is possible. Detection combined with recovery is undesirable, as can have repercussions on file resourcesMain memory : preemption is used but not avoidance as that has run time overheads and resource underutilizationInternal system resources : avoidance or detection will have performance penalties. Prevention by means of resource ordering is typically doneMIT CS704D Advanced OS Class of 201134