Chapter 5 6 Process Synchronization Concurrent Processes Understanding
- Slides: 40
Chapter 5 & 6 Process Synchronization & Concurrent Processes Understanding Operating Systems, 8 e © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 1
Chapter 6 Concurrent Processes Understanding Operating Systems, 8 e © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 2
Learning Objectives After completing this chapter, you should be able to describe: • The differences among common configurations of multiprocessing systems • How processes and processors compare • How multi-core processor technology works • How a critical region aids process synchronization • Process synchronization software essential concepts • How several processors work cooperatively together • How jobs, processes, and threads are executed • How concurrent programming languages manage tasks © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 3
Overview © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 4
What Is Parallel Processing? (1 of 3) • Parallel processing or Multiprocessing • Two or more processors operate in one system at the same time - Work may or may not be related • OR • Two or more CPUs execute instructions simultaneously • Processor Manager - Coordinates activity of each processor - Synchronizes interaction among CPUs © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 5
CPU in Socket Slot Motherboard with 2 CPU Socket 6
What Is Parallel Processing? (2 of 3) • Benefits: • Increased reliability - More than one CPU that can share the load - If one processor fails, others take over: must be designed into the system • Faster processing - Instructions processed in parallel two or more at a time © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 7
What Is Parallel Processing? (3 of 3) • Faster instruction processing methods • CPU allocated to each program or job • CPU allocated to each working set or parts of it • Individual instructions subdivided - Each subdivision processed simultaneously - Concurrent programming • Two major challenges • Connecting processors into workable configurations • Orchestrating processor interaction © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 8
Levels of Multiprocessing (1 of 2) • Multiprocessing occurs at three levels • Job level • Process level • Thread level • Each level requires different synchronization frequency © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 9
Levels of Multiprocessing (2 of 2) (table 6. 2) Typical levels of parallelism and the required synchronization among processors. © Cengage Learning 2018 © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 10
Introduction to Multi-Core Processors • Multi-core processing • Several processors placed on single chip • Problems solved • Current leakage (tunneling) and heat • Solution • Single chip with two processor cores in same space - Allows two sets of simultaneous calculations • Two cores each run more slowly than single core chip … but together better than one. © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 11
Process Synchronization Software • Successful process synchronization • Lock up resource in used - Protect from other processes until released • Only when resource is released - Waiting process is allowed to use resource • Mistakes in synchronization can result in: • Starvation - Leave job waiting indefinitely • Deadlock - If key resource is being used © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 12
Concurrent Programming • Another type of multiprocessing • Concurrent processing system • One job uses several processors - Executes sets of instructions in parallel • Requires programming language and computer system support © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 13
Threads and Concurrent Programming (1 of 2) • Threads: lightweight processes • Smaller unit within process - Scheduled and executed • Minimizes overhead • Swapping process between main memory and secondary storage • Each active process thread • Processor registers, program counter, stack, and status • Shares the data area and resources allocated to its process © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 14
Threads and Concurrent Programming (2 of 2) • Web server: improved performance and interactivity with threads • Requests for images or pages: each served with a different thread • After thread’s task completed: thread returned to pool for assignment to another task © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 15
Conclusion (1 of 2) • Multiprocessing • Single-processor systems - Interacting processes obtain control of CPU at different times • Systems with two or more CPUs - Control synchronized by processor manager - Processor communication and cooperation • System configuration - Master/slave, loosely coupled, and symmetric • Synchronize processes using hardware and software mechanisms © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 16
Conclusion (2 of 2) • Multiprocessing: several configurations • Single-processor with interacting processes • Multiple processors: synchronized by Process Manager • Avoid typical problems of synchronization • Missed waiting customers • Synchronization of producers and consumers • Mutual exclusion of readers and writers • Concurrent processing innovations • Threads and multi-core processors © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 17
Chapter 5 Process Synchronization Understanding Operating Systems, 8 e © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 18
Learning Objectives After completing this chapter, you should be able to describe: • How system deadlock and livelock can occur • How processes can become deadlocked • How to detect and recover from deadlocks • How to detect and recover from starvation • The concept of a race and how to prevent it © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 19
Consequences of Poor Synchronization (1 of 3) • Resource sharing perspectives • Memory management and processor sharing • Many programs competing for limited resources • Lack of process synchronization consequences • Deadlock • Livelock • Starvation © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 20
Consequences of Poor Synchronization (1 of 3) • Narrow staircase analogy • Staircase = system; steps and landings = resources • Stairs: only wide enough for one person • Landing at each floor: room for two people • Deadlock: two people meet on the stairs • Neither retreats • Livelock: two people on a landing • Each time one takes a step to the side, the other mirrors that step; neither moves forward • Starvation: people wait on landing for a break to go up the stairs • Break never comes © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 21
Consequences of Poor Synchronization (2 of 3) • Affects entire system (Deadlocks & Livelocks) • Affects more than one job - Not just a few programs • All system resources become unavailable • More prevalent in interactive systems • Real-time systems • Deadlocks quickly become critical situations • OS must prevent or resolve © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 22
Several Examples of a Deadlock • Nonsharable/nonpreemptable resources • Allocated to jobs requiring same type of resources • Resource types locked by competing jobs • File requests • Databases • Dedicated device allocation • Multiple device allocation • Spooling • Disk sharing © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 23
Case 1: Deadlocks on File Requests (1 of 2) • Jobs request and hold files for execution duration • Example (Figure 5. 3) • Two programs (P 1, P 2) and two files (F 1, F 2) • Deadlock sequence - P 1 has access to F 1 and also requires F 2 - P 2 has access to F 2 and also requires F 1 • Deadlock remains until: - One program is closed or - One program is forcibly removed and file is released • Other programs requiring F 1 or F 2 - Put on hold for duration of situation © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 24
Case 1: Deadlocks on File Requests (2 of 2) (figure 5. 3) Case 1. These two processes, shown as circles, are each waiting for a resource, shown as a rectangle, that has already been allocated to the other process. If neither surrenders its resource a deadlock will result. © Cengage Learning 2018 © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 25
Case 2: Deadlocks in Databases (1 of 2) • Two processes access and lock database records • Database Locking • Guarantees data integrity - One user locks out all other database users while working with the database • Three locking levels - Entire database for duration of request - Subsection of database - Individual record until request completed © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 26
Case 2: Deadlocks in Databases (2 of 2) • Example: two processes (P 1 and P 2) • Each needs to update two records (R 1 and R 2) • Deadlock sequence - P 1 accesses R 1 and locks it - P 2 accesses R 2 and locks it - P 1 requests R 2 but locked by P 2 - P 2 requests R 1 but locked by P 1 • Race between processes • Results when locking not used • Causes incorrect final version of data • Depends on process execution order © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 27
Case 3: Deadlocks in Dedicated Device Allocation • Limited number of dedicated devices • Example • Two administrators each running education programs with processes P 1 and P 2, respectively - Need two audio recorders each - Only two audio recorders (R 1 and R 2) available • Deadlock sequence - P 1 requests tape R 1 and gets it - P 2 requests tape R 2 and gets it - P 1 requests tape R 2 but blocked - P 2 requests tape R 1 but blocked © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 28
Case 4: Deadlocks in Multiple Device Allocation (1 of 2) • Several processes request & hold dedicated devices • Example (Figure 5. 5) • Three programs (P 1, P 2, P 3) • Three dedicated devices (scanner, printer, plotter) • Deadlock sequence - P 1 requests and gets scanner - P 2 requests and gets printer - P 3 requests and gets the plotter - P 1 requests printer but blocked - P 2 requests plotter but blocked - P 3 requests scanner but blocked © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 29
Case 4: Deadlocks in Multiple Device Allocation (2 of 2) (figure 5. 5) Case 4. Three processes, shown as circles, are each waiting for a device that has already been allocated to another process, thus creating a deadlock. © Cengage Learning 2018 © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 30
Case 5: Deadlocks in Spooling (1 of 2) • Virtual device • Dedicated device made sharable • Example - Printer: high-speed disk device transfers data between printer and CPU • Spooling • Process - Spooler accepts output from several users - Acts as temporary storage for output - Output resides in spooling system until printer accepts job data © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 31
Case 5: Deadlocks in Spooling (2 of 2) • Deadlock sequence ( e. g. 10 students printing a file at once containing multiple pages ) • Consider the Printer needs all job output before printing begins - Spooling system fills disk space area ( with only partially completed output) - No one job has entire print output in spool area - Results in partially completed output for all jobs - Results in deadlock © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 32
Case 6: Livelock while Disk Sharing (1 of 2) • Competing processes send conflicting commands • Scenario: disk access resulting in livelock • Example (Figure 5. 6) • Two processes • Each process waiting for I/O request - One at Track 20 and one at Track 310 • Deadlock sequence - Arm moves back and forth between Tracks 20 and 310 attempting to fulfill the two competing commands - Neither I/O request is satisfied © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 33
Case 6: Livelock while Disk Sharing (2 of 2) (figure 5. 6) Case 6. Two processes are each waiting for an I/O request to be filled: one at track 20 and one at track 310. But by the time the read/write arm reaches one track, a competing command for the other track has been issued, so neither command is satisfied and livelock occurs. © Cengage Learning 2018 © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 34
Necessary Conditions for Deadlock • Four conditions required for a locked system • Mutual exclusion: allowing only one process access to dedicated resource • Resource holding: not releasing the resource; waiting for other job to retreat • No preemption: lack of temporary reallocation of resources • Circular wait: each process waiting for another to voluntarily release so at least one can continue • All 4 conditions required for deadlock to occur • Resolving deadlock: remove one of the conditions • All four conditions prevented simultaneously ► deadlock can be prevented but difficult to implement © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 35
Strategies for Handling Deadlocks (1 of 2) • Prevention • Prevent occurrence of one condition - Mutual exclusion, resource holding, no preemption, circular wait • Avoidance • Avoid deadlock if it becomes probable - System knows ahead of time • Sequence of requests associated with each active process • Detection • Detect deadlock when it occurs – ( detection algorithm) • Recovery • Resume system normalcy quickly and gracefully © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 36
Strategies for Handling Deadlocks (2 of 2) • Recovery methods • Terminate every job active in system - Restart jobs from beginning • Terminate only jobs involved in deadlock - Ask users to resubmit jobs • Identify jobs involved in deadlock - Terminate jobs one at a time • Stop new jobs from entering system - Allow non-deadlocked jobs to complete - Releases resources when complete © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 37
Starvation • Job execution prevented • Where a single job is prevented from completing its execution because it is wanting for resources that never become available. • Results from conservative resource allocation - Less resource is allocated at first • Starvation avoidance • Implement algorithm tracking how long each job has been waiting for resources (aging) • Starvation detected: block new jobs until starving jobs satisfied • Note: While deadlock affects system wide performance, starvation affects individual jobs or processes. © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 38
Conclusion (1 of 2) • Operating systems • Must dynamically allocate resources while avoiding deadlock and starvation • Four methods for dealing with deadlocks • Prevention, avoidance, detection, and recovery • Prevention • Remove simultaneous occurrence of one or more conditions: system will become deadlock-free • Prevention algorithms - Complex algorithms and high execution overhead © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 39
Conclusion (2 of 2) • Avoidance • Clearly identify safe and unsafe states • Keep reserve resources to guarantee job completion • Disadvantage - System not fully utilized • When there is no prevention support: • System must detect and recover from deadlocks - Detection relies on selection of victim © 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 40
- Concurrent in os
- Synchronization algorithms and concurrent programming
- Process synchronization in os
- Process synchronization in os
- Process synchronization definition
- Process synchronization definition
- Synchronization 作業系統
- Concurrent process model in embedded systems
- Chapter 6 understanding the management process
- The process of evaluating and regulating ongoing activities
- What processes are crucial to the ipde process
- Fast clock to slow clock synchronization
- Is high level synchronization construct
- Data synchronization in tally erp 9
- Multiprocessor synchronization
- Lean synchronization
- Bgp synchronization rule
- Lock free synchronization
- Classical synchronization problems
- Synchronization tool in os
- Basic synchronization principles
- Creo workspace synchronization
- Syncthreads
- Laser synchronization
- Pthread synchronization
- Posix shared memory synchronization
- Synchronization primitives c#
- Linux kernel synchronization
- Linux
- Physical clock synchronization in distributed system
- Wait free synchronization
- Synchronization tools in operating system
- Deming chain reaction
- Parallel computer architecture cmu
- Synchronization matrix
- Dining philosophers problem using monitors java
- Chia 3 threads
- External clock synchronization
- Cornell cs 4414
- Lamport bakery algorithm in distributed system
- Classical problems of synchronization in os