Home >Common Problem >What is the smallest unit of instruction flow when a program is running?

What is the smallest unit of instruction flow when a program is running?

青灯夜游
青灯夜游Original
2022-08-23 14:16:408886browse

"Thread" is the smallest unit of instruction flow when a program is running. A process refers to a program with certain independent functions, and a thread is a part of the process, describing the execution status of the instruction flow; the thread is the smallest unit of the instruction execution flow in the process, and is the basic unit of CPU scheduling. A thread is an execution process of a task (a program segment); a thread does not occupy memory space, it is included in the memory space of the process. Within the same process, multiple threads share the process's resources; a process has at least one thread.

What is the smallest unit of instruction flow when a program is running?

The operating environment of this tutorial: Windows 7 system, Dell G3 computer.

"Thread" is the smallest unit of instruction flow when a program is running.

A process refers to a program with certain independent functions and a dynamic execution process on a data collection. The thread is part of the process and describes the execution status of the instruction flow. It is the smallest unit of instruction execution flow in a process and the basic unit of CPU scheduling.

Thread (Thread): a lightweight process, which is the smallest unit for scheduling by the operating system. A thread is an execution process of a task (a program segment). The thread does not occupy memory space, it is included in the memory space of the process. Within the same process, multiple threads share the resources of the process. A process has at least one thread.

State

When the operating system creates a thread, the thread is in the creation state. When the CPU schedules the thread, the thread is in the running state. At this time, other created or time slices have expired. The threads are in the ready state. Of course, some threads are in the blocked state when performing IO on disk, network, etc. When the operating system destroys the thread, the thread is in the terminated state. In addition, the thread also has a static ready state and a static blocked state. Being in these two states means that the thread is suspended by the operating system. The operating system suspends the thread in order to observe and analyze the thread status.

What is the smallest unit of instruction flow when a program is running?

Features

In a multi-threaded OS, multiple threads are usually included in a process, and each thread is As the basic unit of utilizing the CPU, it is an entity that consumes minimal overhead. Threads have the following properties.

1), Lightweight entities

The entities in the thread basically do not own system resources, but only have some indispensable resources that can ensure independent operation.

Thread entities include programs, data and TCB. Thread is a dynamic concept, and its dynamic characteristics are described by Thread Control Block (TCB).

2), the basic unit of independent scheduling and dispatch.

In a multi-threaded OS, a thread is the basic unit that can run independently, and therefore is also the basic unit of independent scheduling and dispatch. Because threads are very "light", thread switching is very fast and has little overhead (in the same process).

3), can be executed concurrently.

Multiple threads in a process can be executed concurrently, and even all threads in a process can be executed concurrently; similarly, threads in different processes can also be executed concurrently, making full use of and giving full play to The ability of the processor and peripheral devices to work in parallel.

4), shared process resources.

Each thread in the same process can share the resources owned by the process. This is first manifested in: all threads have the same address space (the address space of the process), which means that threads can Access every virtual address in this address space; in addition, you can also access open files, timers, semaphore mechanisms, etc. owned by the process. Since threads in the same process share memory and files, threads communicate with each other without calling the kernel.

For more related knowledge, please visit the FAQ column!

The above is the detailed content of What is the smallest unit of instruction flow when a program is running?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn