06 lcd slide handout 1 - process synchronization pdf
TRANSCRIPT
![Page 1: 06 lcd slide handout 1 - PROCESS SYNCHRONIZATION PDF](https://reader038.vdocument.in/reader038/viewer/2022102917/58eb965d1a28ab79328b4569/html5/thumbnails/1.jpg)
Process Synchronization
Race Conditions
The Critical Section
Semaphores
Classic Synchronization Problems
1 _________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________
*Property of STI J0024
Race conditions usually occur if two or more processes are allowed to modify the same shared variable at the same time.
To prevent race conditions, the operating system must perform process synchronization to guarantee that only one process is updating a shared variable at any one time.
2 __________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________
*Property of STI J0024
part of the process that contains the instruction or instructions that access a shared variable or resource
Figure 6.1 Critical Sections for Process P1 and P2
3 _________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________
*Property of STI J0024
Software solutions to the critical section problem:
SOLUTION 1
Figure 6.2 Critical Sections of Processes P1 and P2 for Solution 1
4 __________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________
![Page 2: 06 lcd slide handout 1 - PROCESS SYNCHRONIZATION PDF](https://reader038.vdocument.in/reader038/viewer/2022102917/58eb965d1a28ab79328b4569/html5/thumbnails/2.jpg)
*Property of STI J0024
SOLUTION 2
Figure 6.3 Critical Section P1 and P2 for Solution 2
5 _________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________
*Property of STI J0024
SOLUTION 3 (Peterson’s Algorithm)
Figure 6.4 Critical Sections of Processes P1 and P2 for Solution 3
6 __________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________
*Property of STI J0024
SOLUTION TO THE CRITICAL SECTION PROBLEM INVOLVING SEVERAL PROCESS ( Bakery Algorithm)
Figure 6.5 Critical Section of Process P1 for the Bakery Algorithm
7 _________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________
*Property of STI J0024
Hardware solutions to the critical section problem:
Disabling interrupts
Special hardware instructions
These instructions are executed atomically (uninterruptible)
Figure 6.6 Definition of test_and set instruction
8 __________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________
![Page 3: 06 lcd slide handout 1 - PROCESS SYNCHRONIZATION PDF](https://reader038.vdocument.in/reader038/viewer/2022102917/58eb965d1a28ab79328b4569/html5/thumbnails/3.jpg)
*Property of STI J0024
Pi
Figure 6.7 Using the test_and_set instruction to solve the critical section problem
9 _________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________
*Property of STI J0024
Semaphore is a tool that can easily be used to solve more complex synchronization problems and does not use busy waiting.
Pi
Figure 6.8 Using Semaphores to Solve the Critical Section Problem
10 ________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________
*Property of STI J0024
The Dining Philosophers Problem
Restrictions:
1. A philosopher cannot start eating unless he has both forks.
2. A philosopher cannot pick up both forks at the same time. He has to do it one at a time.
3. He cannot get the fork that is being used by the philosopher to his right or to his left.
Figure 6.9 The Dining Philosophers Problem
11 ________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________
*Property of STI J0024
Figure 6.10 Solution to the Dining Philosophers Problem
12 ________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________
![Page 4: 06 lcd slide handout 1 - PROCESS SYNCHRONIZATION PDF](https://reader038.vdocument.in/reader038/viewer/2022102917/58eb965d1a28ab79328b4569/html5/thumbnails/4.jpg)
*Property of STI J0024
The Readers and Writers Problem
Figure 6.11 Using Semaphores to Implement a Writer Process
13 ________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________
*Property of STI J0024
Figure 6.12 Using Semaphores to Implement a Reader Process
14 ________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________ ___________________________