| 0 recommended Multitasking means that the system can run multiple processes at the same time, and each process can execute multiple threads at the same time. A process is a running instance of an application that has its own address space. Each process has one main thread, and other threads can be created. A thread is the basic entity that the operating system allocates CPU time The CPU time consumed by each thread is allocated by the system and the system is switched between threads. The thread sharing process's virtual address space in the process can access the process's resources and is in parallel execution state, which is the basic concept of multithreading. the concept of processes and threads A process is an execution process that can be executed concurrently with other programs, and is the basic unit of resource allocation and scheduling for a system. A process is a program that runs on a dataset. That is, the process is a running program and a running activity for the program. The process is a dynamic concept, The idea that a program is static is a collection of instructions. Therefore, the process is dynamic and concurrency. From the static point of view, the process entity consists of a program block, a Process Control block (PCB) and a data block 3 parts, the program block describes the task to be completed by the process, the data block includes the data and workspace that the program needs to execute. The process control block includes the process description information, the control information, the resource management information and the CPU field protection information, etc., which reflects the dynamic characteristics of the process. PCB is the only sign of the process exists, PCB describes the process of the basic situation of the system according to the PCB awareness of the process of existence, the system also through the PCB contained in the variable changes to grasp the status of the process in order to achieve the purpose of controlling the process activities. When you create a process, you should first create its PCB, and then in accordance with the information in the PCB to implement effective management and control of the process. When a process completes its function, the system releases the PCB and the process dies. In general, the process of the PCB structure are all or part of the resident memory. The status of the process is as follows: Ready state: Refers to the state of a process that is assigned to a required resource other than a processor (already has the conditions for execution). A process is in a ready state after it is created, and a process in a ready state can have multiple. Execution status: Refers to the state in which the process occupancy processor is executing on the CPU. In a single CPU system, only one process is running at a time. Blocking status: a process that waits for an event to abandon the processor and enter the waiting state for the processing machine. There can be multiple processes in this state in the system. The state of the process changes with its own propulsion and external changes. A process such as a ready state is checked into execution by the process scheduler, the process of executing state is waiting for an event to occur, and a process waiting for the state waits for the event to come into the ready state. The state of the process can be dynamically converted to each other, but the blocking process cannot go directly to the execution state, the ready state can be dynamically converted to each other, but the blocked process cannot go directly into the execution state, and the process in the ready state cannot go directly into the blocking state. At any time, any process is in and can only be in a state. In a thread-supporting operating system, purebred is an entity in the process and an independent unit for system implementation. A thread has only a few resources that are necessary to run, and it shares the resources owned by the process with other purebred species that belong to the same process. Can be run concurrently between the purebred. When a thread switches, it simply saves and sets the contents of a small number of registers, which does not involve the operation of the memory management, so the cost of the thread switching is much smaller than the process switching (the process state will cause resource transfer and on-site protection, etc.). Multiple threads of the same process share the same address space, which makes it easier to achieve synchronization and communication between purebred. process vs. Thread comparisons Process and thread are the basic units of the program run by the operating system, and the system uses this basic unit to realize the concurrent trunk of the application. The difference between process and thread is as follows: In short, a program must have at least one process, and a process must have at least one thread. The thread partitioning scale is smaller than the process, which makes the multithreaded procedure more concurrent. In addition, the process has a separate internal unit during execution, while multiple threads share memory, which greatly improves the efficiency of the program. Threads are still different from processes during execution. Each independent thread has a program to run the entry, sequential execution sequence, and exit of the program. However, threads cannot be executed independently, and must be dependent on the application, which provides multiple thread execution control by the application. From a logical point of view, multithreading means that multiple parts of an application can be executed concurrently. However, the operating system does not consider multiple threads as multiple independent applications to implement process scheduling and management, as well as resource allocation. This is the important difference between process and thread. the superiority of multithreading technology 1. Fast Association switching Because the operating system-level process exclusively has its own virtual address space, the system must exchange the address space when scheduling the process, so the process switching time is long. Multiple threads within the same program share the same address space, allowing the thread to switch quickly. For example, 10 processes, 10 threads per process, run faster than the 100 processes, the 1 processes 1 threads per process. 2. The system has little extra overhead The management of multiple processes (creation, scheduling, and so on) has a relatively large system overhead. This overhead is significant in applications that need to dynamically create new processes, such as in a server application that creates a new service process in response to a request from each customer. While the management of threads may have overhead, it is much smaller than the process. 3. Communication is easy to achieve In order to achieve collaboration, data exchange between processes or threads is required. For each thread that automatically shares the same address space, all global data can be accessed, so data sharing is automatically realized without any special means. Communication between processes is much more complex. 4. The number of threads is much more than the number of processes Many multitasking operating systems limit the total number of user processes, such as many UNIX versions with a typical value of 40-100, which is far from enough for many concurrent applications. In multithreaded systems, there are a number of threads, but there are many more (OS/2 support 4,096 threads) |