Basic Concepts of Progressive Learning

Sequential and concurrent program characteristics :

    Sequential program features :

        1. Sequential

        2. Enclosed (operating environment closed)

        3. Certainty

        4. Reproducibility

    Concurrent Program Features :

        1. Shareability

        2. Concurrency

        3. Randomness

Process Mutual Exclusion:

    Since processes require shared resources, and some resources need to be mutually exclusive, each process competes to use these resources, and the relationship between processes is process mutual exclusion.

    Some resources in the system are only allowed to be used by one process at a time, and such resources are called critical resources or mutually exclusive resources.

    The program segment that involves mutually exclusive resources in a process is called a critical section.

Process synchronization:

    Process synchronization means that multiple processes need to cooperate with each other to complete a task.

The purpose of inter-process communication:

    Data transfer: A process needs to send its data to another process.

    Resource sharing: The same resources are shared among multiple processes.

    Notification event: A process needs to send a message to another or a group of processes to notify it (them) that some event has occurred (such as notifying the parent process when the process terminates).

    Process control: Some processes want to completely control the execution of another process (such as the Debug process). At this time, the control process hopes to intercept all traps and exceptions of a process, and be able to know its state changes in time.

Inter-process communication classification:

    document

    file lock

    Pipes and named pipes (FIFO)

    signal

    message queue

    Shared memory

    signal

    Mutex

    condition variable

    Read-write lock

    socket

System V IPC & POSIC IPC

    system V IPC:

        system V message queue

        system V shared memory

        system V semaphore

    POSIX IPC:

        message queue

        Shared memory

        signal

        Mutex

        condition variable

        Read-write lock

Persistence of IPC objects:

    Persistent with process: exists until the last process opened ends. (like pipe and FIFO)

    Persist with Kernel: Lasts until the kernel is bootstrapped or explicitly removed. (such as system V message queue, shared memory, semaphore)

    Persist with filesystem: persists until explicit removal, even if kernel bootstrap exists. (POSIX message queues, shared memory, and semaphores are implemented using mapped files).

Deadlock:

    Deadlock refers to a phenomenon in which multiple processes wait for each other's resources, but do not release their own resources until they obtain each other's resources, thus resulting in a phenomenon of circular waiting. If all processes are waiting for an impossibility to happen, the process is deadlocked. 

Necessary conditions for deadlock to occur:

    Mutually exclusive conditions:

        A process uses a resource exclusively, that is, a resource is occupied by only one process for a period of time.    

    Request and Hold Conditions: 

        When the resources obtained by the process cannot be deprived before they are used up, they can only be released by themselves when they are used up.

    Loop wait condition:

        Each process forms a closed circular chain, and each process waits for the resources occupied by the next process.

Ways to prevent deadlock:

    One-time allocation of resources (destroying request and hold conditions)

    Prescribing resources: destroying inalienable conditions

    Resource orderly allocation method: (destroy the circular waiting condition)

Deadlock avoidance:

    Several strategies for preventing deadlocks can seriously damage system performance. Therefore, when avoiding deadlock, a weaker restriction should be imposed, so as to obtain a relatively satisfactory system performance.

    Due to the strategy of avoiding deadlock, the process is allowed to apply for resources dynamically. Thus, the system pre-computes the security of resource allocation before making resource allocation. If the allocation does not cause the system to enter an unsafe state, the resource is allocated to the process; otherwise, the process waits. One of the most representative algorithms to avoid deadlock is the banker's algorithm.

signal:

    The semaphore and the P and V primitives were proposed by Dijkstra.

    signal:

        Mutual exclusion: P and V are in the same process.

        Synchronization: P, V are in different processes.

    Semaphores and their meanings:

        s>0:s indicates the number of available resources

        s=0: Indicates that there are no available resources and no waiting processes.

        s<0:|s| indicates the number of processes in the waiting queue.  



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324646559&siteId=291194637