SlideShare a Scribd company logo
1 of 33
CS 704DAdvanced Operating System Debasis Das
Process Synchronization MIT    CS704D Advanced OS           Class of 2011 2
Topics Concept of processes Concurrent processes Threads Overview of classical synchronization problems Monitors Communicating Sequential processes MIT    CS704D Advanced OS           Class of 2011 3
Concept of Processes MIT    CS704D Advanced OS           Class of 2011 4
Denning’s DefinitionofOperating Systems(1983) OS is a computer software that assists hardware to perform following process management functions Creating and destroying processes Controlling progress towards completion Acting on arithmetic and  other exceptions Allocating hardware resources Providing communications by messages and signals among processes MIT    CS704D Advanced OS           Class of 2011 5
Implicit & Explicit Tasking Implicit tasking (system defined) Where the OS creates the processes to manage its own work Explicit tasking(programmer defined) Defined by programmer to create concurrent processes to make the execution of the program faster Driving I/O that have latency User convenience Multiprocessing Distributed computing MIT    CS704D Advanced OS           Class of 2011 6
Process Relationship Competition Competes for resources for completion Careful resource allocation and protection Controlled sharing of data and exchange of sync signals Cooperation Shares resources, attributes; interacts Family processes, parent-child processes  MIT    CS704D Advanced OS           Class of 2011 7
Process Control Block Process id Priority State (ready, running, suspended) Hardware state (processor registers, flags) Scheduling information, usage statistics Memory management information (registers, tables) I/O status (allocated devices, pending operations) File management information (open files, access rights) Accounting information MIT    CS704D Advanced OS           Class of 2011 8
Process Lists Linked lists of PCBs One list for ready processes One for suspended  One of running- trivial in case of uniprocessor MIT    CS704D Advanced OS           Class of 2011 9
Process Switch Mode switch Record state of current process; PC, SP,PSW, and all program accessible registers Update PCB data; state, reason for preemption or suspension, measure processor usage Invoke scheduler to start a relevant process Get PCB data to prepare running of the process Restore hardware state, calculate interrupt mask Establish pointers to active files, resource lists Update memory management registers MIT    CS704D Advanced OS           Class of 2011 10
Process Switching Efficiency Hardware assists Have hardware set of registers identical in structure to PCB and  Threads or lightweight processes MIT    CS704D Advanced OS           Class of 2011 11
Threads A lightweight process with reduced state A group of related threads can share resources such as memory and files Separate flow of control with its own stack and hardware state Programmer driven concurrency Switching between threads from different processes costs the same as switching processes MIT    CS704D Advanced OS           Class of 2011 12
OS ServicesforProcess Management Create (processID, attributes) Delete (processID) Fork/Join  Abort (processID) Suspend (processID) Resume (processID) Delay (processID, time) Get_Attributes (processID, attribute_set) Change_Priority (processID, new_priority) MIT    CS704D Advanced OS           Class of 2011 13
Schedulers MIT    CS704D Advanced OS           Class of 2011 14 Suspended & Swapped out queue Medium term scheduler Short term  scheduler Long term scheduler Batch jobs CPU Batch Queue Ready Queue Interactive programs Suspended  queue
Scheduling performance Criteria Processor utilization Throughput Turnaround time Waiting time Response time MIT    CS704D Advanced OS           Class of 2011 15
Scheduling  Algorithms Preemptive, Non preemptive First come first served (FCFS) Shortest remaining time next (SRTN) Time slice or Round Robin or RR Priority based event driven preemptive,  (event driven, ED) Multiple level Queues, MLQ MLQ with feedback MIT    CS704D Advanced OS           Class of 2011 16
Concurrent Processes MIT    CS704D Advanced OS           Class of 2011 17
Inter-process Synchronization Cooperating processes need to synchronize with each other when resources need to be shared-shared data structures or physical device. Following interactions needed Inter-process synchronization For serially reusable resources Inter-process signaling Exchange of signals to help synchronization Inter-process communication Exchanging data, reporting progress, accumulating collective result MIT    CS704D Advanced OS           Class of 2011 18
Problem Example {Process Keyboard} Echo= echo+1 ----------------------------------- {Process Display}} Echo=echo-1 ------------------------------------ Load R, echo Dec   R Store Echo, R  MIT    CS704D Advanced OS           Class of 2011 19
Desirable features ofMutual Exclusion Mutual exclusion between processes accessing protected shared resource Relative speeds and priorities of contending processes can never be assumed Crashes outside the critical section should not prevent other processes from accessing the shared resource When contention arises access must be granted to one in finite time MIT    CS704D Advanced OS           Class of 2011 20
Basic Protocol Following sequence must be used (negotiation protocol)---winner goes ahead (Critical section)--Only one process uses  the resource (Release protocol)—Ownership released MIT    CS704D Advanced OS           Class of 2011 21
Algorithm #1 Code as in Milan Milenkovic, p 93 Problems Identity of adversary is known There is a strict sequence (P1, P2) If one of them crashes, the other will have to keep waiting For multiple contending processes this could get complex MIT    CS704D Advanced OS           Class of 2011 22
Algorithm #2 Code as in Milan Milenkovic, p 96 Improvement No turn taking is forced Problems More than one process may be in the critical section MIT    CS704D Advanced OS           Class of 2011 23
Algorithm #3 Code as in Milan Milenkovic, p 98 Improvement No two processes can be in the CS at the same time Problem Both can get into an indefinite loop MIT    CS704D Advanced OS           Class of 2011 24
Semaphores Wait; decrement value of semaphore if it is non negative. Wait operation is indivisible Signal; increment the value of semaphore, operation is indivisible -------------------------------- Binary semaphores and  general or counting semaphore MIT    CS704D Advanced OS           Class of 2011 25
Wait & signal operations wait(s): while not (s>0) do (keeptesting)                  s:=s-1 --------------------------------- signal(s): s:=s+1 Implementation Code in Milan Milenkovic, p 100 Advantages Meets all the criteria for mutual exclusion MIT    CS704D Advanced OS           Class of 2011 26
Properties & Characteristics Processes need not even be aware of number of competitors Modification of code in one process  does not need changes in another Semaphores can be in Programming language or as service calls in OS Create_Semaphore, Attach_To_Semaphore, Wait, Signal, Close_Semaphore are some calls that can be implemented MIT    CS704D Advanced OS           Class of 2011 27
Service Discipline Required to avoid indefinite postponement or livelock or starvation Discipline policy has to avoid such starvation  “A request to enter a critical section must be granted in finite time” must be enforced FCFS policy ensure everyone gets a turn  MIT    CS704D Advanced OS           Class of 2011 28
Semaphore Granularity Serialization of processes by semaphore can have an impact on performance Granularity of individual semaphores then is an important aspect Finest granularity ensure there is no concurrency timing problems Problems: potentially large storage overhead for storing a large number of semaphores, processing overhead of too many wait & signals Coarse granularity (controlling a set of resources within one Semaphore) Problem: reduces benefits of parallelism MIT    CS704D Advanced OS           Class of 2011 29
Hardware SupportforConcurrency Control Semaphore implementation needs some hardware support Pessimistic & Optimistic concurrency control Disable/enable interrupts Test and set instruction Compare an Swap instruction MIT    CS704D Advanced OS           Class of 2011 30
Pessimistic & OptimisticConcurrency control Pessimistic solution Block everything Update global variable Unblock the part of the system blocked in first step --------------------------------------------------- Optimistic solution Read the value of the global variable, prepare tentative local update based on the value (global variable remains accessible to others) Compare current value of global variable to the value of local update. If the global variable is unchanged, apply local update. If not discard local update. Go to earlier step MIT    CS704D Advanced OS           Class of 2011 31
Tools for Implementationof Semaphores #1 Disable/enable interrupts (but is pessimistic) DI Critical section EI --------------------------- If users have access, it can cause chaos Does not work in multiple processors case  ban use by programmers, only system should use for implementing the wait and signal methods MIT    CS704D Advanced OS           Class of 2011 32
Tools for Implementationof Semaphores #2 Test and Set instruction Wait: TS S              BNF Wait             Return ----------------------------- Wait: Mov AL, 1             XCHG  AL,S              CMP AL, 0               JNZ  Wait               Ret MIT    CS704D Advanced OS           Class of 2011 33

More Related Content

What's hot

Sequences & Control Schemes for Air & Water Systems
Sequences & Control Schemes for Air & Water SystemsSequences & Control Schemes for Air & Water Systems
Sequences & Control Schemes for Air & Water Systems
Illinois ASHRAE
 
Distributed Control System
Distributed Control SystemDistributed Control System
Distributed Control System
3abooodi
 
Challenges in Using UVM at SoC Level
Challenges in Using UVM at SoC LevelChallenges in Using UVM at SoC Level
Challenges in Using UVM at SoC Level
DVClub
 
Dispensing control
Dispensing controlDispensing control
Dispensing control
kukulililabs
 

What's hot (19)

Modern Testing Strategies for Evolving Ecosystems
Modern Testing Strategies for Evolving EcosystemsModern Testing Strategies for Evolving Ecosystems
Modern Testing Strategies for Evolving Ecosystems
 
Dcs course
Dcs courseDcs course
Dcs course
 
3rd 3DDRESD: OSyRIS
3rd 3DDRESD: OSyRIS3rd 3DDRESD: OSyRIS
3rd 3DDRESD: OSyRIS
 
Profibus programming-guide
Profibus programming-guideProfibus programming-guide
Profibus programming-guide
 
Embedded system design process_models
Embedded system design process_modelsEmbedded system design process_models
Embedded system design process_models
 
Sequences & Control Schemes for Air & Water Systems
Sequences & Control Schemes for Air & Water SystemsSequences & Control Schemes for Air & Water Systems
Sequences & Control Schemes for Air & Water Systems
 
Distributed Control System
Distributed Control SystemDistributed Control System
Distributed Control System
 
Challenges in Using UVM at SoC Level
Challenges in Using UVM at SoC LevelChallenges in Using UVM at SoC Level
Challenges in Using UVM at SoC Level
 
System verilog important
System verilog importantSystem verilog important
System verilog important
 
Design of Industrial Automation Functional Specifications for PLCs, DCs and S...
Design of Industrial Automation Functional Specifications for PLCs, DCs and S...Design of Industrial Automation Functional Specifications for PLCs, DCs and S...
Design of Industrial Automation Functional Specifications for PLCs, DCs and S...
 
SERENE 2014 School: Luigi pomante serene2014_school
SERENE 2014 School: Luigi pomante serene2014_schoolSERENE 2014 School: Luigi pomante serene2014_school
SERENE 2014 School: Luigi pomante serene2014_school
 
Integrity Protection for Embedded Systems
Integrity Protection for Embedded SystemsIntegrity Protection for Embedded Systems
Integrity Protection for Embedded Systems
 
ARM 32-bit Microcontroller Cortex-M3 introduction
ARM 32-bit Microcontroller Cortex-M3 introductionARM 32-bit Microcontroller Cortex-M3 introduction
ARM 32-bit Microcontroller Cortex-M3 introduction
 
Soc.pptx
Soc.pptxSoc.pptx
Soc.pptx
 
basil.pptx
basil.pptxbasil.pptx
basil.pptx
 
One Day Version 10.3 Upgrade - How a Large Biotech Plant's DeltaV Systems Wer...
One Day Version 10.3 Upgrade - How a Large Biotech Plant's DeltaV Systems Wer...One Day Version 10.3 Upgrade - How a Large Biotech Plant's DeltaV Systems Wer...
One Day Version 10.3 Upgrade - How a Large Biotech Plant's DeltaV Systems Wer...
 
Dispensing control
Dispensing controlDispensing control
Dispensing control
 
Dcs or plc
Dcs or plcDcs or plc
Dcs or plc
 
Defense
DefenseDefense
Defense
 

Similar to Cs 704 d set2

System on Chip Based RTC in Power Electronics
System on Chip Based RTC in Power ElectronicsSystem on Chip Based RTC in Power Electronics
System on Chip Based RTC in Power Electronics
journalBEEI
 
Cs 704 d set4distributedcomputing-1funda
Cs 704 d set4distributedcomputing-1fundaCs 704 d set4distributedcomputing-1funda
Cs 704 d set4distributedcomputing-1funda
Debasis Das
 
Topic2 Understanding Middleware
Topic2 Understanding MiddlewareTopic2 Understanding Middleware
Topic2 Understanding Middleware
sanjoysanyal
 
Cse viii-advanced-computer-architectures-06cs81-solution
Cse viii-advanced-computer-architectures-06cs81-solutionCse viii-advanced-computer-architectures-06cs81-solution
Cse viii-advanced-computer-architectures-06cs81-solution
Shobha Kumar
 
SDN Controller - Programming Challenges
SDN Controller - Programming ChallengesSDN Controller - Programming Challenges
SDN Controller - Programming Challenges
snrism
 

Similar to Cs 704 d set2 (20)

Advanced Operating System- Introduction
Advanced Operating System- IntroductionAdvanced Operating System- Introduction
Advanced Operating System- Introduction
 
Cs 704 d set3
Cs 704 d set3Cs 704 d set3
Cs 704 d set3
 
Scylla Summit 2016: Scylla at Samsung SDS
Scylla Summit 2016: Scylla at Samsung SDSScylla Summit 2016: Scylla at Samsung SDS
Scylla Summit 2016: Scylla at Samsung SDS
 
System on Chip Based RTC in Power Electronics
System on Chip Based RTC in Power ElectronicsSystem on Chip Based RTC in Power Electronics
System on Chip Based RTC in Power Electronics
 
SFScon 22 - Andrea Janes - Scalability assessment applied to microservice arc...
SFScon 22 - Andrea Janes - Scalability assessment applied to microservice arc...SFScon 22 - Andrea Janes - Scalability assessment applied to microservice arc...
SFScon 22 - Andrea Janes - Scalability assessment applied to microservice arc...
 
Cs 704 d set4distributedcomputing-1funda
Cs 704 d set4distributedcomputing-1fundaCs 704 d set4distributedcomputing-1funda
Cs 704 d set4distributedcomputing-1funda
 
Linux capacity planning
Linux capacity planningLinux capacity planning
Linux capacity planning
 
Low cost embedded system
Low cost embedded systemLow cost embedded system
Low cost embedded system
 
Material of Course Juniper JNCIA JUNOS Day1
Material of Course Juniper JNCIA JUNOS Day1Material of Course Juniper JNCIA JUNOS Day1
Material of Course Juniper JNCIA JUNOS Day1
 
5 Techniques to Achieve Functional Safety for Embedded Systems
5 Techniques to Achieve Functional Safety for Embedded Systems5 Techniques to Achieve Functional Safety for Embedded Systems
5 Techniques to Achieve Functional Safety for Embedded Systems
 
5 Techniques to Achieve Functional Safety for Embedded Systems
5 Techniques to Achieve Functional Safety for Embedded Systems5 Techniques to Achieve Functional Safety for Embedded Systems
5 Techniques to Achieve Functional Safety for Embedded Systems
 
5 Techniques to Achieve Functional Safety for Embedded Systems
5 Techniques to Achieve Functional Safety for Embedded Systems5 Techniques to Achieve Functional Safety for Embedded Systems
5 Techniques to Achieve Functional Safety for Embedded Systems
 
[COSCUP 2022] 腳踏多條船-利用 Coroutine在 Software Transactional Memory上進行動態排程
[COSCUP 2022] 腳踏多條船-利用 Coroutine在  Software Transactional Memory上進行動態排程[COSCUP 2022] 腳踏多條船-利用 Coroutine在  Software Transactional Memory上進行動態排程
[COSCUP 2022] 腳踏多條船-利用 Coroutine在 Software Transactional Memory上進行動態排程
 
Topic2 Understanding Middleware
Topic2 Understanding MiddlewareTopic2 Understanding Middleware
Topic2 Understanding Middleware
 
Performance and how to measure it - ProgSCon London 2016
Performance and how to measure it - ProgSCon London 2016Performance and how to measure it - ProgSCon London 2016
Performance and how to measure it - ProgSCon London 2016
 
Cse viii-advanced-computer-architectures-06cs81-solution
Cse viii-advanced-computer-architectures-06cs81-solutionCse viii-advanced-computer-architectures-06cs81-solution
Cse viii-advanced-computer-architectures-06cs81-solution
 
Embedded Intro India05
Embedded Intro India05Embedded Intro India05
Embedded Intro India05
 
SDN Controller - Programming Challenges
SDN Controller - Programming ChallengesSDN Controller - Programming Challenges
SDN Controller - Programming Challenges
 
SAP consulting results
SAP consulting resultsSAP consulting results
SAP consulting results
 
sap basis transaction codes
sap basis transaction codessap basis transaction codes
sap basis transaction codes
 

More from Debasis Das

More from Debasis Das (20)

Developing robust & enterprise io t applications
Developing robust & enterprise io t applicationsDeveloping robust & enterprise io t applications
Developing robust & enterprise io t applications
 
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
 
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
 
Microprocessors & microcontrollers- The design Context
Microprocessors & microcontrollers- The design ContextMicroprocessors & microcontrollers- The design Context
Microprocessors & microcontrollers- The design Context
 
Management control systems jsb 606 part4
Management control systems jsb 606 part4Management control systems jsb 606 part4
Management control systems jsb 606 part4
 
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
 
Management control systems jsb 606 part1
Management control systems jsb 606 part1Management control systems jsb 606 part1
Management control systems jsb 606 part1
 
Computers for management jsb 1072003 ver
Computers for management jsb 1072003 verComputers for management jsb 1072003 ver
Computers for management jsb 1072003 ver
 
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
 
Ei502microprocessorsmicrtocontrollerspart5 sixteen bit8086 1
Ei502microprocessorsmicrtocontrollerspart5 sixteen bit8086 1Ei502microprocessorsmicrtocontrollerspart5 sixteen bit8086 1
Ei502microprocessorsmicrtocontrollerspart5 sixteen bit8086 1
 
Ei502 microprocessors & micrtocontrollers part3hardwareinterfacing
Ei502 microprocessors & micrtocontrollers part3hardwareinterfacingEi502 microprocessors & micrtocontrollers part3hardwareinterfacing
Ei502 microprocessors & micrtocontrollers part3hardwareinterfacing
 
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
 
It802 d mobilecommunicationspart4
It802 d mobilecommunicationspart4It802 d mobilecommunicationspart4
It802 d mobilecommunicationspart4
 
It802 d mobilecommunicationspart3
It802 d mobilecommunicationspart3It802 d mobilecommunicationspart3
It802 d mobilecommunicationspart3
 
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 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
 

Recently uploaded

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
fonyou31
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Recently uploaded (20)

Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
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
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
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...
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 

Cs 704 d set2

  • 1. CS 704DAdvanced Operating System Debasis Das
  • 2. Process Synchronization MIT CS704D Advanced OS Class of 2011 2
  • 3. Topics Concept of processes Concurrent processes Threads Overview of classical synchronization problems Monitors Communicating Sequential processes MIT CS704D Advanced OS Class of 2011 3
  • 4. Concept of Processes MIT CS704D Advanced OS Class of 2011 4
  • 5. Denning’s DefinitionofOperating Systems(1983) OS is a computer software that assists hardware to perform following process management functions Creating and destroying processes Controlling progress towards completion Acting on arithmetic and other exceptions Allocating hardware resources Providing communications by messages and signals among processes MIT CS704D Advanced OS Class of 2011 5
  • 6. Implicit & Explicit Tasking Implicit tasking (system defined) Where the OS creates the processes to manage its own work Explicit tasking(programmer defined) Defined by programmer to create concurrent processes to make the execution of the program faster Driving I/O that have latency User convenience Multiprocessing Distributed computing MIT CS704D Advanced OS Class of 2011 6
  • 7. Process Relationship Competition Competes for resources for completion Careful resource allocation and protection Controlled sharing of data and exchange of sync signals Cooperation Shares resources, attributes; interacts Family processes, parent-child processes MIT CS704D Advanced OS Class of 2011 7
  • 8. Process Control Block Process id Priority State (ready, running, suspended) Hardware state (processor registers, flags) Scheduling information, usage statistics Memory management information (registers, tables) I/O status (allocated devices, pending operations) File management information (open files, access rights) Accounting information MIT CS704D Advanced OS Class of 2011 8
  • 9. Process Lists Linked lists of PCBs One list for ready processes One for suspended One of running- trivial in case of uniprocessor MIT CS704D Advanced OS Class of 2011 9
  • 10. Process Switch Mode switch Record state of current process; PC, SP,PSW, and all program accessible registers Update PCB data; state, reason for preemption or suspension, measure processor usage Invoke scheduler to start a relevant process Get PCB data to prepare running of the process Restore hardware state, calculate interrupt mask Establish pointers to active files, resource lists Update memory management registers MIT CS704D Advanced OS Class of 2011 10
  • 11. Process Switching Efficiency Hardware assists Have hardware set of registers identical in structure to PCB and Threads or lightweight processes MIT CS704D Advanced OS Class of 2011 11
  • 12. Threads A lightweight process with reduced state A group of related threads can share resources such as memory and files Separate flow of control with its own stack and hardware state Programmer driven concurrency Switching between threads from different processes costs the same as switching processes MIT CS704D Advanced OS Class of 2011 12
  • 13. OS ServicesforProcess Management Create (processID, attributes) Delete (processID) Fork/Join Abort (processID) Suspend (processID) Resume (processID) Delay (processID, time) Get_Attributes (processID, attribute_set) Change_Priority (processID, new_priority) MIT CS704D Advanced OS Class of 2011 13
  • 14. Schedulers MIT CS704D Advanced OS Class of 2011 14 Suspended & Swapped out queue Medium term scheduler Short term scheduler Long term scheduler Batch jobs CPU Batch Queue Ready Queue Interactive programs Suspended queue
  • 15. Scheduling performance Criteria Processor utilization Throughput Turnaround time Waiting time Response time MIT CS704D Advanced OS Class of 2011 15
  • 16. Scheduling Algorithms Preemptive, Non preemptive First come first served (FCFS) Shortest remaining time next (SRTN) Time slice or Round Robin or RR Priority based event driven preemptive, (event driven, ED) Multiple level Queues, MLQ MLQ with feedback MIT CS704D Advanced OS Class of 2011 16
  • 17. Concurrent Processes MIT CS704D Advanced OS Class of 2011 17
  • 18. Inter-process Synchronization Cooperating processes need to synchronize with each other when resources need to be shared-shared data structures or physical device. Following interactions needed Inter-process synchronization For serially reusable resources Inter-process signaling Exchange of signals to help synchronization Inter-process communication Exchanging data, reporting progress, accumulating collective result MIT CS704D Advanced OS Class of 2011 18
  • 19. Problem Example {Process Keyboard} Echo= echo+1 ----------------------------------- {Process Display}} Echo=echo-1 ------------------------------------ Load R, echo Dec R Store Echo, R MIT CS704D Advanced OS Class of 2011 19
  • 20. Desirable features ofMutual Exclusion Mutual exclusion between processes accessing protected shared resource Relative speeds and priorities of contending processes can never be assumed Crashes outside the critical section should not prevent other processes from accessing the shared resource When contention arises access must be granted to one in finite time MIT CS704D Advanced OS Class of 2011 20
  • 21. Basic Protocol Following sequence must be used (negotiation protocol)---winner goes ahead (Critical section)--Only one process uses the resource (Release protocol)—Ownership released MIT CS704D Advanced OS Class of 2011 21
  • 22. Algorithm #1 Code as in Milan Milenkovic, p 93 Problems Identity of adversary is known There is a strict sequence (P1, P2) If one of them crashes, the other will have to keep waiting For multiple contending processes this could get complex MIT CS704D Advanced OS Class of 2011 22
  • 23. Algorithm #2 Code as in Milan Milenkovic, p 96 Improvement No turn taking is forced Problems More than one process may be in the critical section MIT CS704D Advanced OS Class of 2011 23
  • 24. Algorithm #3 Code as in Milan Milenkovic, p 98 Improvement No two processes can be in the CS at the same time Problem Both can get into an indefinite loop MIT CS704D Advanced OS Class of 2011 24
  • 25. Semaphores Wait; decrement value of semaphore if it is non negative. Wait operation is indivisible Signal; increment the value of semaphore, operation is indivisible -------------------------------- Binary semaphores and general or counting semaphore MIT CS704D Advanced OS Class of 2011 25
  • 26. Wait & signal operations wait(s): while not (s>0) do (keeptesting) s:=s-1 --------------------------------- signal(s): s:=s+1 Implementation Code in Milan Milenkovic, p 100 Advantages Meets all the criteria for mutual exclusion MIT CS704D Advanced OS Class of 2011 26
  • 27. Properties & Characteristics Processes need not even be aware of number of competitors Modification of code in one process does not need changes in another Semaphores can be in Programming language or as service calls in OS Create_Semaphore, Attach_To_Semaphore, Wait, Signal, Close_Semaphore are some calls that can be implemented MIT CS704D Advanced OS Class of 2011 27
  • 28. Service Discipline Required to avoid indefinite postponement or livelock or starvation Discipline policy has to avoid such starvation “A request to enter a critical section must be granted in finite time” must be enforced FCFS policy ensure everyone gets a turn MIT CS704D Advanced OS Class of 2011 28
  • 29. Semaphore Granularity Serialization of processes by semaphore can have an impact on performance Granularity of individual semaphores then is an important aspect Finest granularity ensure there is no concurrency timing problems Problems: potentially large storage overhead for storing a large number of semaphores, processing overhead of too many wait & signals Coarse granularity (controlling a set of resources within one Semaphore) Problem: reduces benefits of parallelism MIT CS704D Advanced OS Class of 2011 29
  • 30. Hardware SupportforConcurrency Control Semaphore implementation needs some hardware support Pessimistic & Optimistic concurrency control Disable/enable interrupts Test and set instruction Compare an Swap instruction MIT CS704D Advanced OS Class of 2011 30
  • 31. Pessimistic & OptimisticConcurrency control Pessimistic solution Block everything Update global variable Unblock the part of the system blocked in first step --------------------------------------------------- Optimistic solution Read the value of the global variable, prepare tentative local update based on the value (global variable remains accessible to others) Compare current value of global variable to the value of local update. If the global variable is unchanged, apply local update. If not discard local update. Go to earlier step MIT CS704D Advanced OS Class of 2011 31
  • 32. Tools for Implementationof Semaphores #1 Disable/enable interrupts (but is pessimistic) DI Critical section EI --------------------------- If users have access, it can cause chaos Does not work in multiple processors case ban use by programmers, only system should use for implementing the wait and signal methods MIT CS704D Advanced OS Class of 2011 32
  • 33. Tools for Implementationof Semaphores #2 Test and Set instruction Wait: TS S BNF Wait Return ----------------------------- Wait: Mov AL, 1 XCHG AL,S CMP AL, 0 JNZ Wait Ret MIT CS704D Advanced OS Class of 2011 33