The relationship between threads and processes: Each process has a corresponding thread. When executing a program, a series of corresponding threads are actually executed. A process is the smallest unit of resource allocation, and a thread is the smallest unit of program execution.
#The operating environment of this article: windows10 system, thinkpad t480 computer.
What is the relationship between threads and processes?
The fundamental difference:
The process is the smallest unit of resource allocation, and the thread is the smallest unit of program execution. When the computer executes a program, it will create a corresponding process for the program. When allocating resources, the corresponding allocation is performed in units of processes. Each process has a corresponding thread. When executing a program, a corresponding series of threads are actually executed.
Address space:
The process has its own independent address space. Every time a process is started, the system will allocate an address space to it and establish a data table to maintain the code segment, stack segment and data segment; Threads do not have independent address spaces. Threads in the same process share the address space of this process.
Resource ownership:
The resources between processes are independent; threads in the same process share the resources of this process.
Execution process:
Each independent process has an entrance for program running, a sequential execution sequence and a program entrance. However, threads cannot execute independently and must exist in the application program, and the application program provides multiple thread execution control.
Threads are the basic unit of processor scheduling, but processes are not. Since the process of program execution is actually the execution of specific threads, the processor also processes the threads corresponding to the program, so the basic unit of processor scheduling is the thread.
System overhead:
Process execution overhead is large, and thread execution overhead is small.
(Learning video sharing: Programming video)
The above is the detailed content of What is the relationship between threads and processes. For more information, please follow other related articles on the PHP Chinese website!