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.
Second, the semaphore mechanism
1. Integer semaphore
2. Recorded semaphore
Three, the semaphore mechanism realizes process synchronization
The semaphore mechanism realizes the precursor relationship
Fourth, the application of semaphore mechanism
1. The problem of production, consumption and readers
2. Multiple (class) producers-multiple (class) consumers problem
Code implementation:
Thinking: Can the problem meet the requirements of the problem if mutual exclusion semaphores are not used?
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
Solution:
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.
Five, control process
1. The composition of the pipeline
2. The basic characteristics of the pipeline
The definition of the
tube : the call
of the tube: a summary of the tube:
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:
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.
4. Deadlock processing strategy
Breach of inalienable conditions
Break request and hold condition
Break the loop waiting condition
Apply in order of number, irreversible or random
Seven, banker algorithm (to avoid deadlock)
Data structure implemented by the code:
8. Detection and removal of deadlock
Need to remove the deadlock