SlideShare a Scribd company logo
1 of 34
CS 704DAdvanced Operating System Debasis Das
Tools for Implementationof Semaphores #3 Compare & Swap Instructions Helps consistent update of global variable Implementation Compare Oldreg, Globvar Set condition codes If (Oldreg=Globvar) Then Globvar Newreg                                        Else OldregGlobvar MIT    CS704D Advanced OS           Class of 2011 2
Queuing Implementationof Semaphore MIT    CS704D Advanced OS           Class of 2011 3 Semaphore Pz ….. Py Px Wait(s):  If not (s>0) then suspend caller at s                  else s:= s+1 Signal (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 problems Producers and consumers With unbounded buffers With bounded buffers Readers and writers MIT    CS704D Advanced OS           Class of 2011 4
Producers & Consumers One class of processes produce data items The other class consumes/uses this data They may have different rates and thus cause synchronization problems Synchronizations required so that producers & consumers are able to operate concurrently Such that items produced are consumed in the same order Display, keyboard was an example Processes may be a combination of both producer and consumer MIT    CS704D Advanced OS           Class of 2011 5
Producers & Consumers(unbounded buffer case) If we can prevent a process trying to consume something before at least one item is available, sync is achieved A semaphore “Producer” can take care of that We assume buffer manipulation does not cause problems This is not really a valid assumption in multiple producer, consumer situations MIT    CS704D Advanced OS           Class of 2011 6
Unbounded Buffer Case A mutex controlling buffer access can manage the situation well How the mutex is used exactly can have unintended implications If the waiting on “producer” is placed within the critical section, there can be deadlocks Initially, for example, when nothing has been produced and a consumer is scheduled, the consumer will get through to the critical section Then wait forever on Producer as a producer process cannot get into the critical section MIT    CS704D Advanced OS           Class of 2011 7
Producers & Consumers(bounded buffer case) Additional management issues are that the buffers are to be controlled Producers should not produce when buffer is full, it will overwrite some existing data Consumers, similarly will consume wrong data if buffer is empty These conditions have to be controlled MIT    CS704D Advanced OS           Class of 2011 8
Unbounded case  Icount=produced-consumed Necessary that icount cannot be  less than zero and more than the capacity Then Condition mayproduce : icount < capacity  as also  mayconsume: icount>0 MIT    CS704D Advanced OS           Class of 2011 9
Readers & Writers Readers and consumers are processes that operate against some common data structure Readers are pure readers, only reads parts or all of the data structure Writers write and thus modify the data structure. It can also read the structure or parts of it Readers thus can safely get interleaved with other readers But writes cannot be interleaved with other readers or writers MIT    CS704D Advanced OS           Class of 2011 10
The sync Problem Given a universe of readers that read a common data structure, and a universe of writers that modify the same common data structure A sync mechanism needs to be devised to control readers and writers to ensure consistency of common data  and maintain as high  a concurrency as possible MIT    CS704D Advanced OS           Class of 2011 11
Example Synchronization High concurrency Allows high number of readers to access common resource Writer waits for the wait semaphore Reader process makes it possible for multiple readers to work Readercount really tracks if even one reader is active Next round, the writer gets  turn only when all readers finished reading, that may be unfair MIT    CS704D Advanced OS           Class of 2011 12
Suggested Modifications(according to C A R Hoare) A reader should not start if there’s a writer waiting, preventing starvation for writers All readers waiting at the end of a write cycle should be given priority, preventing starvation of  readers MIT    CS704D Advanced OS           Class of 2011 13
Inter-process Communication& Synchronization MIT    CS704D Advanced OS           Class of 2011 14
Semaphore Problems Sync 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 system Semaphores 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 2011 15
Critical Regions & Conditional critical Regions Strong typing and compile time checks can prevent some of the problems For example var mutex : shared T; and critical section as follows  region mutex do The compiler can ensure wait and signals are introduced properly, no probability of errors MIT    CS704D Advanced OS           Class of 2011 16
Why condionality required Sometimes a process getting access to the CS may still need some condition to be fulfilled and thus block other processing entering the CS Conditional CS construct can prevent such problems MIT    CS704D Advanced OS           Class of 2011 17
Conditional Critical Region var mutex: shared T; begin  region  v do begin await condition end; End; Special queue is maintained, allowed only when the condition is met MIT    CS704D Advanced OS           Class of 2011 18
Monitor MIT    CS704D Advanced OS           Class of 2011 19 Enforce concurrency Processes Processes Access, modify shared variable(s)
Monitors-Plus Minus Can regulate a group of related resources too If this is too many, the serialization  overhead could be too much Same things can be done at kernel level Serialization overheads will cause problems very quickly as kernel controls all kinds of resources Writing, building, debugging such monolithic structures could be problematic Monitors can create a  deadlock Monitor disciplines may restrict application programmers MIT    CS704D Advanced OS           Class of 2011 20
Messages A collection of data, execution commands, sometimes even code Interchanged between sending and receiving processes MIT    CS704D Advanced OS           Class of 2011 21 Sender id Receiver id Length Header Type …… Message body
Issues in Message Implementation Naming Direct, indirect  (mailbox) Copying Copy message, pass  pointer Synchronous/asynchronous Synchronous can be blocking, asynchronous can cause runaway,  indefinite postponement Length Fixed or variable length  (overhead vs. flexibility) MIT    CS704D Advanced OS           Class of 2011 22
Inter-process Communication & sync with Messages Assume buffered message, infinite channel capacity, indirect naming (via mailboxes) Sender  send s the message & continues, receiver will be suspended if no message Sync through semaphore like operation of messages. Signal send a message to waiting on semaphore, wait is just waiting to receive a message Sync also can be through messages Example; producer waits for a message through mayproduce mailbox, a consumer  gets a  mayconsume MIT    CS704D Advanced OS           Class of 2011 23
Interrupt Signaling via Message A message (signal) can initiate a set of waiting interrupt service processes Interrupt service need not be treated differently from other processes Hardware interrupts that need guaranteed response time, may be a problem All software interrupts can be handled this way MIT    CS704D Advanced OS           Class of 2011 24
Deadlocks A 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 2011 25
Necessary Conditions Mutual 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 acquired No preemption.  Resources are released only when given up by the owner Circular waiting. Each process hold one or more resources being requested by the next process in the chain MIT    CS704D Advanced OS           Class of 2011 26
Reusable & Consumable Resources Reusable. Resources that can be safely used by one process at any time. It is either available or allocated to a process It can only be relinquished by the owner Single resource multiple instances, multiple resources of single instance Consumable 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 2011 27
Deadlock Prevention-1 Hold-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 execution Asks for resources as needed but relinquishes resources held by it when a requested resource is not available Overestimation of resources, holding on to resources longer than necessary Reduces concurrency, resources are underutilized MIT    CS704D Advanced OS           Class of 2011 28
Deadlock Prevention-2 No-preemptionissue can obviously be solved by allowing preemption OS will need to save the state of the process For 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 system Apply such policies only when the benefits of deadlock prevention is more than the cost of save & restore of state of some resources MIT    CS704D Advanced OS           Class of 2011 29
Deadlock Prevention-3 Circular 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 problems Disadvantages All resources must be acquired up front Lower degree of concurrency and lower utilization of resources MIT    CS704D Advanced OS           Class of 2011 30
Deadlock Avoidance Grant resources only if the request is not likely to cause deadlocks A resource allocator must examine the implications All processes must proclaim maximum need When 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 2011 31
Deadlock detection & Recovery If the general resource  graph has a cycle or a knot then deadlock exists Rollback or restarting can be options State needs to be known Some systems have check pointing or journaling system, one could use that MIT    CS704D Advanced OS           Class of 2011 32
Combined Approach Typical classes of devices Swap area Job resources & assignable devices Main 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 used MIT    CS704D Advanced OS           Class of 2011 33
Combined Policies Swap space: advance booking of all swap space. Dead lock detection is not possible Job resources: pre-claiming of resources, Resource ordering also is possible. Detection combined with recovery is undesirable, as can have repercussions on file resources Main memory : preemption is used but not avoidance as that has run time overheads and resource underutilization Internal system resources : avoidance or detection will have performance penalties. Prevention by means of resource ordering is typically done MIT    CS704D Advanced OS           Class of 2011 34

More Related Content

Viewers also liked

It802 d mobilecommunicationspart4
It802 d mobilecommunicationspart4It802 d mobilecommunicationspart4
It802 d mobilecommunicationspart4Debasis Das
 
Cs704 d distributedschedulingetc.
Cs704 d distributedschedulingetc.Cs704 d distributedschedulingetc.
Cs704 d distributedschedulingetc.Debasis Das
 
It802 d mobilecommunicationspart3
It802 d mobilecommunicationspart3It802 d mobilecommunicationspart3
It802 d mobilecommunicationspart3Debasis Das
 
The Life Of Taylor Stanley
The Life Of Taylor StanleyThe Life Of Taylor Stanley
The Life Of Taylor Stanleyguest9be325b
 
Management control systems jsb 606 part4
Management control systems jsb 606 part4Management control systems jsb 606 part4
Management control systems jsb 606 part4Debasis Das
 
Evolution of Social Media Marketing - Tom Edwards
Evolution of Social Media Marketing - Tom EdwardsEvolution of Social Media Marketing - Tom Edwards
Evolution of Social Media Marketing - Tom EdwardsTom Edwards
 
Management control systems jsb 606 part1
Management control systems jsb 606 part1Management control systems jsb 606 part1
Management control systems jsb 606 part1Debasis Das
 
IoT: An Introduction and Getting Started Session
IoT: An Introduction and Getting Started SessionIoT: An Introduction and Getting Started Session
IoT: An Introduction and Getting Started SessionDebasis Das
 
Ei502 microprocessors & micrtocontrollers part3hardwareinterfacing
Ei502 microprocessors & micrtocontrollers part3hardwareinterfacingEi502 microprocessors & micrtocontrollers part3hardwareinterfacing
Ei502 microprocessors & micrtocontrollers part3hardwareinterfacingDebasis Das
 
Microprocessors & microcontrollers- The design Context
Microprocessors & microcontrollers- The design ContextMicroprocessors & microcontrollers- The design Context
Microprocessors & microcontrollers- The design ContextDebasis Das
 
Trends in education management
Trends in education managementTrends in education management
Trends in education managementDebasis Das
 
Ei502microprocessorsmicrtocontrollerspart4 8051 Microcontroller
Ei502microprocessorsmicrtocontrollerspart4 8051 MicrocontrollerEi502microprocessorsmicrtocontrollerspart4 8051 Microcontroller
Ei502microprocessorsmicrtocontrollerspart4 8051 MicrocontrollerDebasis Das
 
Advanced Operating System- Introduction
Advanced Operating System- IntroductionAdvanced Operating System- Introduction
Advanced Operating System- IntroductionDebasis Das
 

Viewers also liked (14)

It802 d mobilecommunicationspart4
It802 d mobilecommunicationspart4It802 d mobilecommunicationspart4
It802 d mobilecommunicationspart4
 
Cs704 d distributedschedulingetc.
Cs704 d distributedschedulingetc.Cs704 d distributedschedulingetc.
Cs704 d distributedschedulingetc.
 
It802 d mobilecommunicationspart3
It802 d mobilecommunicationspart3It802 d mobilecommunicationspart3
It802 d mobilecommunicationspart3
 
The Life Of Taylor Stanley
The Life Of Taylor StanleyThe Life Of Taylor Stanley
The Life Of Taylor Stanley
 
Management control systems jsb 606 part4
Management control systems jsb 606 part4Management control systems jsb 606 part4
Management control systems jsb 606 part4
 
Cs 704 d rpc
Cs 704 d rpcCs 704 d rpc
Cs 704 d rpc
 
Evolution of Social Media Marketing - Tom Edwards
Evolution of Social Media Marketing - Tom EdwardsEvolution of Social Media Marketing - Tom Edwards
Evolution of Social Media Marketing - Tom Edwards
 
Management control systems jsb 606 part1
Management control systems jsb 606 part1Management control systems jsb 606 part1
Management control systems jsb 606 part1
 
IoT: An Introduction and Getting Started Session
IoT: An Introduction and Getting Started SessionIoT: An Introduction and Getting Started Session
IoT: An Introduction and Getting Started Session
 
Ei502 microprocessors & micrtocontrollers part3hardwareinterfacing
Ei502 microprocessors & micrtocontrollers part3hardwareinterfacingEi502 microprocessors & micrtocontrollers part3hardwareinterfacing
Ei502 microprocessors & micrtocontrollers part3hardwareinterfacing
 
Microprocessors & microcontrollers- The design Context
Microprocessors & microcontrollers- The design ContextMicroprocessors & microcontrollers- The design Context
Microprocessors & microcontrollers- The design Context
 
Trends in education management
Trends in education managementTrends in education management
Trends in education management
 
Ei502microprocessorsmicrtocontrollerspart4 8051 Microcontroller
Ei502microprocessorsmicrtocontrollerspart4 8051 MicrocontrollerEi502microprocessorsmicrtocontrollerspart4 8051 Microcontroller
Ei502microprocessorsmicrtocontrollerspart4 8051 Microcontroller
 
Advanced Operating System- Introduction
Advanced Operating System- IntroductionAdvanced Operating System- Introduction
Advanced Operating System- Introduction
 

Similar to Cs 704 d set3

Cs 704 d set4distributedcomputing-1funda
Cs 704 d set4distributedcomputing-1fundaCs 704 d set4distributedcomputing-1funda
Cs 704 d set4distributedcomputing-1fundaDebasis Das
 
Processes, Threads and Scheduler
Processes, Threads and SchedulerProcesses, Threads and Scheduler
Processes, Threads and SchedulerMunazza-Mah-Jabeen
 
Scalable Apache for Beginners
Scalable Apache for BeginnersScalable Apache for Beginners
Scalable Apache for Beginnerswebhostingguy
 
Foundational Design Patterns for Multi-Purpose Applications
Foundational Design Patterns for Multi-Purpose ApplicationsFoundational Design Patterns for Multi-Purpose Applications
Foundational Design Patterns for Multi-Purpose ApplicationsChing-Hwa Yu
 
Operating system Interview Questions
Operating system Interview QuestionsOperating system Interview Questions
Operating system Interview QuestionsKuntal Bhowmick
 
Tef con2016 (1)
Tef con2016 (1)Tef con2016 (1)
Tef con2016 (1)ggarber
 
Concurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and SynchronizationConcurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and SynchronizationAnas Ebrahim
 
LM9 - OPERATIONS, SCHEDULING, Inter process xommuncation
LM9 - OPERATIONS, SCHEDULING, Inter process xommuncationLM9 - OPERATIONS, SCHEDULING, Inter process xommuncation
LM9 - OPERATIONS, SCHEDULING, Inter process xommuncationMani Deepak Choudhry
 
Lecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfLecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfAmanuelmergia
 
Demystifying the use of circuit breakers with MuleSoft
Demystifying the use of circuit breakers with MuleSoftDemystifying the use of circuit breakers with MuleSoft
Demystifying the use of circuit breakers with MuleSoftSandeep Deshmukh
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronizationlodhran-hayat
 
Debugging Microservices - QCON 2017
Debugging Microservices - QCON 2017Debugging Microservices - QCON 2017
Debugging Microservices - QCON 2017Idit Levine
 
Beyond the RTOS: A Better Way to Design Real-Time Embedded Software
Beyond the RTOS: A Better Way to Design Real-Time Embedded SoftwareBeyond the RTOS: A Better Way to Design Real-Time Embedded Software
Beyond the RTOS: A Better Way to Design Real-Time Embedded SoftwareQuantum Leaps, LLC
 
Operating System- INTERPROCESS COMMUNICATION.docx
Operating System- INTERPROCESS COMMUNICATION.docxOperating System- INTERPROCESS COMMUNICATION.docx
Operating System- INTERPROCESS COMMUNICATION.docxminaltmv
 
Monitor(karthika)
Monitor(karthika)Monitor(karthika)
Monitor(karthika)Nagarajan
 
Data Virtualization Deployments: How to Manage Very Large Deployments
Data Virtualization Deployments: How to Manage Very Large DeploymentsData Virtualization Deployments: How to Manage Very Large Deployments
Data Virtualization Deployments: How to Manage Very Large DeploymentsDenodo
 
HbaseHivePigbyRohitDubey
HbaseHivePigbyRohitDubeyHbaseHivePigbyRohitDubey
HbaseHivePigbyRohitDubeyRohit Dubey
 
Multithreading 101
Multithreading 101Multithreading 101
Multithreading 101Tim Penhey
 
Naveen nimmu sdn future of networking
Naveen nimmu sdn   future of networkingNaveen nimmu sdn   future of networking
Naveen nimmu sdn future of networkingOpenSourceIndia
 

Similar to Cs 704 d set3 (20)

Chapter05 new
Chapter05 newChapter05 new
Chapter05 new
 
Cs 704 d set4distributedcomputing-1funda
Cs 704 d set4distributedcomputing-1fundaCs 704 d set4distributedcomputing-1funda
Cs 704 d set4distributedcomputing-1funda
 
Processes, Threads and Scheduler
Processes, Threads and SchedulerProcesses, Threads and Scheduler
Processes, Threads and Scheduler
 
Scalable Apache for Beginners
Scalable Apache for BeginnersScalable Apache for Beginners
Scalable Apache for Beginners
 
Foundational Design Patterns for Multi-Purpose Applications
Foundational Design Patterns for Multi-Purpose ApplicationsFoundational Design Patterns for Multi-Purpose Applications
Foundational Design Patterns for Multi-Purpose Applications
 
Operating system Interview Questions
Operating system Interview QuestionsOperating system Interview Questions
Operating system Interview Questions
 
Tef con2016 (1)
Tef con2016 (1)Tef con2016 (1)
Tef con2016 (1)
 
Concurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and SynchronizationConcurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and Synchronization
 
LM9 - OPERATIONS, SCHEDULING, Inter process xommuncation
LM9 - OPERATIONS, SCHEDULING, Inter process xommuncationLM9 - OPERATIONS, SCHEDULING, Inter process xommuncation
LM9 - OPERATIONS, SCHEDULING, Inter process xommuncation
 
Lecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfLecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdf
 
Demystifying the use of circuit breakers with MuleSoft
Demystifying the use of circuit breakers with MuleSoftDemystifying the use of circuit breakers with MuleSoft
Demystifying the use of circuit breakers with MuleSoft
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 
Debugging Microservices - QCON 2017
Debugging Microservices - QCON 2017Debugging Microservices - QCON 2017
Debugging Microservices - QCON 2017
 
Beyond the RTOS: A Better Way to Design Real-Time Embedded Software
Beyond the RTOS: A Better Way to Design Real-Time Embedded SoftwareBeyond the RTOS: A Better Way to Design Real-Time Embedded Software
Beyond the RTOS: A Better Way to Design Real-Time Embedded Software
 
Operating System- INTERPROCESS COMMUNICATION.docx
Operating System- INTERPROCESS COMMUNICATION.docxOperating System- INTERPROCESS COMMUNICATION.docx
Operating System- INTERPROCESS COMMUNICATION.docx
 
Monitor(karthika)
Monitor(karthika)Monitor(karthika)
Monitor(karthika)
 
Data Virtualization Deployments: How to Manage Very Large Deployments
Data Virtualization Deployments: How to Manage Very Large DeploymentsData Virtualization Deployments: How to Manage Very Large Deployments
Data Virtualization Deployments: How to Manage Very Large Deployments
 
HbaseHivePigbyRohitDubey
HbaseHivePigbyRohitDubeyHbaseHivePigbyRohitDubey
HbaseHivePigbyRohitDubey
 
Multithreading 101
Multithreading 101Multithreading 101
Multithreading 101
 
Naveen nimmu sdn future of networking
Naveen nimmu sdn   future of networkingNaveen nimmu sdn   future of networking
Naveen nimmu sdn future of networking
 

More from Debasis Das

Developing robust &amp; enterprise io t applications
Developing robust &amp; enterprise io t applicationsDeveloping robust &amp; enterprise io t applications
Developing robust &amp; enterprise io t applicationsDebasis Das
 
Development eco-system in free-source for io t
Development eco-system in free-source for io tDevelopment eco-system in free-source for io t
Development eco-system in free-source for io tDebasis Das
 
Management control systems jsb 606 part3
Management control systems jsb 606 part3Management control systems jsb 606 part3
Management control systems jsb 606 part3Debasis Das
 
Management control systems jsb 606 part2
Management control systems jsb 606 part2Management control systems jsb 606 part2
Management control systems jsb 606 part2Debasis Das
 
Computers for management jsb 1072003 ver
Computers for management jsb 1072003 verComputers for management jsb 1072003 ver
Computers for management jsb 1072003 verDebasis Das
 
Ei502microprocessorsmicrtocontrollerspart5 sixteen bit8086 1
Ei502microprocessorsmicrtocontrollerspart5 sixteen bit8086 1Ei502microprocessorsmicrtocontrollerspart5 sixteen bit8086 1
Ei502microprocessorsmicrtocontrollerspart5 sixteen bit8086 1Debasis Das
 
Ei502 microprocessors & micrtocontrollers part 2(instructionset)
Ei502 microprocessors & micrtocontrollers part 2(instructionset)Ei502 microprocessors & micrtocontrollers part 2(instructionset)
Ei502 microprocessors & micrtocontrollers part 2(instructionset)Debasis Das
 
Ei502 microprocessors & micrtocontrollers part 1
Ei502 microprocessors & micrtocontrollers part 1Ei502 microprocessors & micrtocontrollers part 1
Ei502 microprocessors & micrtocontrollers part 1Debasis Das
 
It 802 d_Mobile Communications_part 2
It 802 d_Mobile Communications_part 2It 802 d_Mobile Communications_part 2
It 802 d_Mobile Communications_part 2Debasis Das
 
It 802 d_mobile_communicationsSomeHistory
It 802 d_mobile_communicationsSomeHistoryIt 802 d_mobile_communicationsSomeHistory
It 802 d_mobile_communicationsSomeHistoryDebasis Das
 
It 802 d_intro&wlan
It 802 d_intro&wlanIt 802 d_intro&wlan
It 802 d_intro&wlanDebasis Das
 
It 802 d_intro&wlan
It 802 d_intro&wlanIt 802 d_intro&wlan
It 802 d_intro&wlanDebasis Das
 
Cs704 d distributedmutualexcclusion&memory
Cs704 d distributedmutualexcclusion&memoryCs704 d distributedmutualexcclusion&memory
Cs704 d distributedmutualexcclusion&memoryDebasis Das
 
Cs 704 d aos-resource&processmanagement
Cs 704 d aos-resource&processmanagementCs 704 d aos-resource&processmanagement
Cs 704 d aos-resource&processmanagementDebasis Das
 
Cs 704 d dce ipc-msgpassing
Cs 704 d dce ipc-msgpassingCs 704 d dce ipc-msgpassing
Cs 704 d dce ipc-msgpassingDebasis Das
 

More from Debasis Das (15)

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

Recently uploaded

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Recently uploaded (20)

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 

Cs 704 d set3

  • 1. CS 704DAdvanced Operating System Debasis Das
  • 2. Tools for Implementationof Semaphores #3 Compare & Swap Instructions Helps consistent update of global variable Implementation Compare Oldreg, Globvar Set condition codes If (Oldreg=Globvar) Then Globvar Newreg Else OldregGlobvar MIT CS704D Advanced OS Class of 2011 2
  • 3. Queuing Implementationof Semaphore MIT CS704D Advanced OS Class of 2011 3 Semaphore Pz ….. Py Px Wait(s): If not (s>0) then suspend caller at s else s:= s+1 Signal (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 problems Producers and consumers With unbounded buffers With bounded buffers Readers and writers MIT CS704D Advanced OS Class of 2011 4
  • 5. Producers & Consumers One class of processes produce data items The other class consumes/uses this data They may have different rates and thus cause synchronization problems Synchronizations required so that producers & consumers are able to operate concurrently Such that items produced are consumed in the same order Display, keyboard was an example Processes may be a combination of both producer and consumer MIT CS704D Advanced OS Class of 2011 5
  • 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 achieved A semaphore “Producer” can take care of that We assume buffer manipulation does not cause problems This is not really a valid assumption in multiple producer, consumer situations MIT CS704D Advanced OS Class of 2011 6
  • 7. Unbounded Buffer Case A mutex controlling buffer access can manage the situation well How the mutex is used exactly can have unintended implications If the waiting on “producer” is placed within the critical section, there can be deadlocks Initially, for example, when nothing has been produced and a consumer is scheduled, the consumer will get through to the critical section Then wait forever on Producer as a producer process cannot get into the critical section MIT CS704D Advanced OS Class of 2011 7
  • 8. Producers & Consumers(bounded buffer case) Additional management issues are that the buffers are to be controlled Producers should not produce when buffer is full, it will overwrite some existing data Consumers, similarly will consume wrong data if buffer is empty These conditions have to be controlled MIT CS704D Advanced OS Class of 2011 8
  • 9. Unbounded case Icount=produced-consumed Necessary that icount cannot be less than zero and more than the capacity Then Condition mayproduce : icount < capacity as also mayconsume: icount>0 MIT CS704D Advanced OS Class of 2011 9
  • 10. Readers & Writers Readers and consumers are processes that operate against some common data structure Readers are pure readers, only reads parts or all of the data structure Writers write and thus modify the data structure. It can also read the structure or parts of it Readers thus can safely get interleaved with other readers But writes cannot be interleaved with other readers or writers MIT CS704D Advanced OS Class of 2011 10
  • 11. The sync Problem Given a universe of readers that read a common data structure, and a universe of writers that modify the same common data structure A sync mechanism needs to be devised to control readers and writers to ensure consistency of common data and maintain as high a concurrency as possible MIT CS704D Advanced OS Class of 2011 11
  • 12. Example Synchronization High concurrency Allows high number of readers to access common resource Writer waits for the wait semaphore Reader process makes it possible for multiple readers to work Readercount really tracks if even one reader is active Next round, the writer gets turn only when all readers finished reading, that may be unfair MIT CS704D Advanced OS Class of 2011 12
  • 13. Suggested Modifications(according to C A R Hoare) A reader should not start if there’s a writer waiting, preventing starvation for writers All readers waiting at the end of a write cycle should be given priority, preventing starvation of readers MIT CS704D Advanced OS Class of 2011 13
  • 14. Inter-process Communication& Synchronization MIT CS704D Advanced OS Class of 2011 14
  • 15. Semaphore Problems Sync 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 system Semaphores 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 2011 15
  • 16. Critical Regions & Conditional critical Regions Strong typing and compile time checks can prevent some of the problems For example var mutex : shared T; and critical section as follows region mutex do The compiler can ensure wait and signals are introduced properly, no probability of errors MIT CS704D Advanced OS Class of 2011 16
  • 17. Why condionality required Sometimes a process getting access to the CS may still need some condition to be fulfilled and thus block other processing entering the CS Conditional CS construct can prevent such problems MIT CS704D Advanced OS Class of 2011 17
  • 18. Conditional Critical Region var mutex: shared T; begin region v do begin await condition end; End; Special queue is maintained, allowed only when the condition is met MIT CS704D Advanced OS Class of 2011 18
  • 19. Monitor MIT CS704D Advanced OS Class of 2011 19 Enforce concurrency Processes Processes Access, modify shared variable(s)
  • 20. Monitors-Plus Minus Can regulate a group of related resources too If this is too many, the serialization overhead could be too much Same things can be done at kernel level Serialization overheads will cause problems very quickly as kernel controls all kinds of resources Writing, building, debugging such monolithic structures could be problematic Monitors can create a deadlock Monitor disciplines may restrict application programmers MIT CS704D Advanced OS Class of 2011 20
  • 21. Messages A collection of data, execution commands, sometimes even code Interchanged between sending and receiving processes MIT CS704D Advanced OS Class of 2011 21 Sender id Receiver id Length Header Type …… Message body
  • 22. Issues in Message Implementation Naming Direct, indirect (mailbox) Copying Copy message, pass pointer Synchronous/asynchronous Synchronous can be blocking, asynchronous can cause runaway, indefinite postponement Length Fixed or variable length (overhead vs. flexibility) MIT CS704D Advanced OS Class of 2011 22
  • 23. Inter-process Communication & sync with Messages Assume buffered message, infinite channel capacity, indirect naming (via mailboxes) Sender send s the message & continues, receiver will be suspended if no message Sync through semaphore like operation of messages. Signal send a message to waiting on semaphore, wait is just waiting to receive a message Sync also can be through messages Example; producer waits for a message through mayproduce mailbox, a consumer gets a mayconsume MIT CS704D Advanced OS Class of 2011 23
  • 24. Interrupt Signaling via Message A message (signal) can initiate a set of waiting interrupt service processes Interrupt service need not be treated differently from other processes Hardware interrupts that need guaranteed response time, may be a problem All software interrupts can be handled this way MIT CS704D Advanced OS Class of 2011 24
  • 25. Deadlocks A 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 2011 25
  • 26. Necessary Conditions Mutual 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 acquired No preemption. Resources are released only when given up by the owner Circular waiting. Each process hold one or more resources being requested by the next process in the chain MIT CS704D Advanced OS Class of 2011 26
  • 27. Reusable & Consumable Resources Reusable. Resources that can be safely used by one process at any time. It is either available or allocated to a process It can only be relinquished by the owner Single resource multiple instances, multiple resources of single instance Consumable 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 2011 27
  • 28. Deadlock Prevention-1 Hold-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 execution Asks for resources as needed but relinquishes resources held by it when a requested resource is not available Overestimation of resources, holding on to resources longer than necessary Reduces concurrency, resources are underutilized MIT CS704D Advanced OS Class of 2011 28
  • 29. Deadlock Prevention-2 No-preemptionissue can obviously be solved by allowing preemption OS will need to save the state of the process For 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 system Apply such policies only when the benefits of deadlock prevention is more than the cost of save & restore of state of some resources MIT CS704D Advanced OS Class of 2011 29
  • 30. Deadlock Prevention-3 Circular 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 problems Disadvantages All resources must be acquired up front Lower degree of concurrency and lower utilization of resources MIT CS704D Advanced OS Class of 2011 30
  • 31. Deadlock Avoidance Grant resources only if the request is not likely to cause deadlocks A resource allocator must examine the implications All processes must proclaim maximum need When 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 2011 31
  • 32. Deadlock detection & Recovery If the general resource graph has a cycle or a knot then deadlock exists Rollback or restarting can be options State needs to be known Some systems have check pointing or journaling system, one could use that MIT CS704D Advanced OS Class of 2011 32
  • 33. Combined Approach Typical classes of devices Swap area Job resources & assignable devices Main 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 used MIT CS704D Advanced OS Class of 2011 33
  • 34. Combined Policies Swap space: advance booking of all swap space. Dead lock detection is not possible Job resources: pre-claiming of resources, Resource ordering also is possible. Detection combined with recovery is undesirable, as can have repercussions on file resources Main memory : preemption is used but not avoidance as that has run time overheads and resource underutilization Internal system resources : avoidance or detection will have performance penalties. Prevention by means of resource ordering is typically done MIT CS704D Advanced OS Class of 2011 34