[Review notes] Synchronization and mutual exclusion of operating system processes

1. Basic concepts

Process synchronization: synchronization constraints also known as direct relationship, refers to two or more processes to accomplish a task and established, these processes because of the need in some locations to coordinate their work order constraints arising from the relationship. The direct restrictive relationship between processes stems from their cooperation.
Mutual exclusion: means that when a process accesses a critical resource when you want to access another process must wait for the current access to critical resources, the end of the process to access, after the release of the resource, another process to access critical resources.
Insert picture description here

Second, the semaphore mechanism

1. Integer semaphore

Insert picture description here

2. Recorded semaphore

Insert picture description here

Insert picture description here
Insert picture description here

Three, the semaphore mechanism realizes process synchronization

Insert picture description here
The semaphore mechanism realizes the precursor relationship
Insert picture description here
Insert picture description here

Fourth, the application of semaphore mechanism

1. The problem of production, consumption and readers
2. Multiple (class) producers-multiple (class) consumers problem

Insert picture description here
Code implementation:
Insert picture description here
Thinking: Can the problem meet the requirements of the problem if mutual exclusion semaphores are not used?
Insert picture description here
It can meet the requirements of the problem, mainly because the capacity of the plate is 1. If the capacity of the plate is greater than 1, you must use the mutex mutex semaphoremutex

3. The philosopher's meal problem

Insert picture description here
Solution:

Insert picture description here
Set the mutex mutex semaphorem u t e x makes each philosopher mutually exclusive to pick up chopsticks, and pick up two chopsticks at a time.

Insert picture description here

Five, control process

1. The composition of the pipeline

Insert picture description here

2. The basic characteristics of the pipeline

Insert picture description here

The definition of the
Insert picture description here
tube : the call
Insert picture description here
of the tube: a summary of the tube:

Insert picture description here
Insert picture description here

Six, deadlock (Dead Lock)

1. Definition: In a concurrent environment, each process is waiting for resources in the hands of each other due to competition for resources, causing each process to be blocked and unable to move forward .

2. The difference between deadlock, starvation, and endless loop:

Insert picture description here
Deadlock and starvation do not occupy the processor, and the infinite loop must occupy the processor.

One or more processes can be starved, while a deadlock can only be a deadlock of multiple processes at the same time.

3. Necessary conditions for deadlock

A deadlock must meet the following four conditions at the same time, as long as one of them is not established, the deadlock will not occur.

Insert picture description here

4. Deadlock processing strategy

Insert picture description here
Breach of inalienable conditions

Insert picture description here

Break request and hold condition

Insert picture description here
Insert picture description here
Break the loop waiting condition

Apply in order of number, irreversible or random

Insert picture description here
Insert picture description here

Seven, banker algorithm (to avoid deadlock)

Insert picture description here
Data structure implemented by the code:

Insert picture description here

8. Detection and removal of deadlock

Insert picture description here

Insert picture description here

Need to remove the deadlock

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_42500831/article/details/107938809