SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Destaque

Cs704 d distributedschedulingetc.
Cs704 d distributedschedulingetc.Cs704 d distributedschedulingetc.
Cs704 d distributedschedulingetc.
Debasis Das
 
The Life Of Taylor Stanley
The Life Of Taylor StanleyThe Life Of Taylor Stanley
The Life Of Taylor Stanley
guest9be325b
 

Destaque (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
 

Semelhante a Cs 704 d set3

Cs 704 d set4distributedcomputing-1funda
Cs 704 d set4distributedcomputing-1fundaCs 704 d set4distributedcomputing-1funda
Cs 704 d set4distributedcomputing-1funda
Debasis Das
 
Scalable Apache for Beginners
Scalable Apache for BeginnersScalable Apache for Beginners
Scalable Apache for Beginners
webhostingguy
 
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
Ching-Hwa Yu
 
Lecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfLecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdf
Amanuelmergia
 
Monitor(karthika)
Monitor(karthika)Monitor(karthika)
Monitor(karthika)
Nagarajan
 
HbaseHivePigbyRohitDubey
HbaseHivePigbyRohitDubeyHbaseHivePigbyRohitDubey
HbaseHivePigbyRohitDubey
Rohit Dubey
 
Naveen nimmu sdn future of networking
Naveen nimmu sdn   future of networkingNaveen nimmu sdn   future of networking
Naveen nimmu sdn future of networking
OpenSourceIndia
 

Semelhante a 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
 

Mais de Debasis Das

It 802 d_intro&wlan
It 802 d_intro&wlanIt 802 d_intro&wlan
It 802 d_intro&wlan
Debasis Das
 
Cs 704 d dce ipc-msgpassing
Cs 704 d dce ipc-msgpassingCs 704 d dce ipc-msgpassing
Cs 704 d dce ipc-msgpassing
Debasis Das
 

Mais de 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
 

Último

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Último (20)

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

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