What are Protostomes?
Control of computer processes is usually done by primitives. The so-called primitives generally refer to a program segment composed of several instructions, which is used to implement a specific function and cannot be interrupted during execution. In the operating system, certain operations called by processes, such as queue operations, operations on semaphores, and checking and starting peripheral operations, cannot be interrupted once they start executing, otherwise operation errors will occur and cause system confusion. Therefore, these operations must be implemented using primitives. Primitives are an integral part of the operating system core (not a process, but a set of program modules), and are resident in memory and are usually executed in a piped state. Once the primitive is started, it must be executed continuously without interruption [1] .
- Primitives are instructions that call core-level subroutines in the operating system. It differs from generalized instructions in that it is uninterruptible and always appears as a basic unit. It differs from normal processes in that they are "
- The term "primitive" is also used in computer networks, which is different from the "primitive" concept of operating systems. The service primitive refers to the primitive operation sent by the lower layer protocol in the protocol to provide some service for the upper layer protocol through the interface.
- The primitives are divided into four categories: request (Req) type primitives, which are used by higher layers to request a certain service from the lower layers; confirmation (Cfm) type primitives, which are used by layers that provide services to confirm that an action has been completed; and (Ind) The type primitive is used by the layer providing the service to report an action related to a specific service to the upper layer; the response (Res) type primitive is used in response to indicate that the indication primitive from the upper layer has been received.
- Primitives usually consist of several instructions to achieve a specific operation. Its function is realized by an indivisible or uninterruptible program. Primitives are the core of the operating system, not by a process but by a group
- Asynchronous primitives are also called asynchronous communication primitives, which refer to another communication primitive called non-blocking that corresponds to a blocked communication primitive. If a send primitive is non-blocking, it returns control to the caller immediately before the message is actually sent. In other words, the sending process does not enter a blocking state when sending a message. It does not wait for the message to be sent before continuing to execute its subsequent statements. The advantages of asynchronous primitives (also known as non-blocking primitives) are obvious. The sending process can do continuous work during the actual sending of the message, instead of letting the CPU idle (assuming no other processes can run at this time). That is to say, the use of non-blocking communication primitives can greatly improve the efficiency of the system and the utilization of the processor. However, the efficiency benefits of non-blocking primitives are offset by a serious disadvantage. This disadvantage is that the buffer can be used once because the sender cannot continue to use the original buffer until the sender has finished sending the message. Given the terrible consequences of modifying the buffer during messaging, it is not known when this buffer will be allowed to be used [3]
- The main task of process control is to implement effective management and control of all processes in the system from creation to death. This means that it not only manages and controls process state changes, but also has the ability to create new processes and undo processes that have completed tasks.
- In order to control the process, a mechanism must be set in the operating system, which has the ability to create processes, undo processes, and other management functions. This is the most common and core content in the operating system, often called the kernel. The kernel is the first layer of expansion software of computer hardware, and it is the management and control center of the operating system. Its functions are often implemented by performing various primitive operations. To ensure the correctness of the operation, the primitives are indivisible during execution. Once the primitive is started, it is not allowed to be interrupted until it is finished. In the operating system, the primitives used for process control are mainly creation primitives, undo primitives, blocking primitives, and wakeup primitives [3]
- PV primitives handle the issues of synchronization and mutual exclusion between processes by manipulating semaphores. At its core is an indivisible and uninterruptible program. The concept of a semaphore was proposed by the well-known Dutch computer scientist Dijkstra in 1965. The basic idea is to use a new variable type (semaphore) to record the number of currently available resources. There are two ways to implement semaphore:
- 1) The value of semaphore must be greater than or equal to 0. 0 means that there are currently no free resources, and a positive number means the number of current free resources;
- 2) The value of semaphore can be positive or negative. The absolute value of a negative number indicates the number of processes waiting to enter the critical section.
- Semaphores are maintained by the operating system, and user processes can only be accessed through initialization and two standard primitives (P, V primitives). Initialization can specify a non-negative integer, which is the total number of free resources.
P Primitive P
- P is the first letter of the Dutch Passeren. For the blocking primitive, it is responsible for transitioning the current process from the running state to the blocking state until another process wakes it up. [4] The operation is: apply for an idle resource (decrease the semaphore by 1), if it succeeds, exit; if it fails, the process is blocked;
V Primitive V Primitive
- V is the initial letter of the Dutch Verhogen (increase). To wake up the primitive, it is responsible for awakening a blocked process. It has a parameter table that stores information about the process waiting to be awakened. The operation is: release an occupied resource (increase the semaphore by 1), and if a blocked process is found, choose one to wake it up.
- The actions of the P primitive operation are:
- (1) sem minus 1;
- (2) If sem is still greater than or equal to zero after subtracting 1, the P primitive is returned and the process continues to execute;
- (3) If sem is less than zero after decrementing by 1, the process is blocked and enters the queue corresponding to the signal, and then transfers to process scheduling.
- The actions of the V primitive operation are:
- (1) sem plus 1;
- (2) If the addition result is greater than zero, the V primitive stops execution, the process returns to the call and continues execution;
- (3) If the addition result is less than or equal to zero, wake up a waiting process from the waiting queue of the signal, and then return to the original process to continue execution or transfer to process scheduling.
- PV operations can only be performed once for each process and must be used in pairs. No interrupts are allowed during PV primitive execution.
- The operation of semaphores by specific PV primitives can be divided into three cases:
- 1) Treat the semaphore as a lock flag to achieve mutually exclusive access to a shared variable.
- Implementation process:
- P (mutex); // initial value of mutex is 1 to access the shared data; V (mutex); non-critical region;
- 2) Treat semaphores as the remaining number of shared resources of a certain type to achieve access to a shared resource of a certain type.
- Implementation process:
- P (resource); // The initial value of resource is the number of the resource N to use the resource; V (resource); non-critical region;
- 3) Use semaphores as a synchronization tool between processes
- Implementation process:
- Critical region C1; P (S); V (S); critical region C2;