The basic unit of CPU scheduling is the thread. A thread is the smallest unit that the operating system can perform operation scheduling.
#A thread refers to a single sequential control flow in a process. Multiple threads can run concurrently in a process, and each thread performs different tasks in parallel. It is also called lightweight processes in Unix System V and SunOS, but lightweight processes refer more to kernel threads, while user threads are called threads. (Recommended learning: web front-end video tutorial)
CPU Scheduler
Whenever the CPU is idle, the operation must be selected from the ready queue a process to execute. Process selection is performed by a short-term scheduler or CPU scheduler. The scheduler selects an executable process from the kernel and allocates the CPU to it.
The ready queue does not have to be a first-in-first-out (FIFO) queue. Ready queues can be implemented as FIFO queues, priority queues, trees, or simple unordered linked lists. Conceptually, however, all processes in the ready queue are queued to wait to run on the CPU. Records in the queue are usually process control blocks (PCBs).
Preemptive Scheduling
CPU scheduling decisions can occur in the following 4 environments:
When a process changes from the running state Switch to a waiting state (for example, an I/O request, or calling wait to wait for the termination of a child process).
When a process switches from the running state to the ready state (for example, when an interrupt occurs)
When a process switches from the waiting state to the ready state (for example, I/O is completed)
When a process terminates
For cases 1 and 4, there is no choice but scheduling. A new process (if a process already exists in the ready queue) must be selected for execution. However, for cases 2 and 3, there is a choice.
When scheduling can only occur in the 1st and 4th situations, the scheduling plan is called nonpreemptive or cooperative; otherwise, the scheduling plan is called preemptive. ). With non-preemptive scheduling, once the CPU is allocated to a process, the process will always use the CPU until the process terminates or switches to a waiting state.
Interrupts can occur at any time and cannot always be ignored by the kernel, so the code segments affected by interrupts must be protected from simultaneous access. In order to prevent these code segments from being accessed by multiple processes at the same time, interrupts must be disabled when entering, and interrupts must be re-enabled when exiting.
The above is the detailed content of The smallest unit of processor scheduling. For more information, please follow other related articles on the PHP Chinese website!