A thread is a single sequential control flow in a process that is also a lightweight process (lightweight processes) is the basic unit of CPU dispatch and dispatch, the process is the basis of the operating system structure, is an executing program, a running program instance on the computer, An entity that can be assigned to a processor and executed by the processor, displayed by a single order of execution, a current state, and a set of related system resources described by the active unit. Also known as the heavyweight process (heavyweight processes)
Compare threads and processes from scheduling, concurrency, system overhead, owning resources, and more
Scheduling
In the traditional operating system, the basic unit of CPU dispatch and dispatch is a process, and in the operating system that introduces the thread as the basic unit of CPU dispatch and dispatch, the process acts as the basic unit of the resource, so that the two attributes of the traditional process are separated and the thread can run lightly. This can significantly improve the concurrency of the system. Switching between threads in the same process does not cause the process to switch, which avoids expensive system calls, but it can cause the process to switch when a thread in one process switches to a thread in another process.
Concurrency of
In the operating system that introduces the thread, not only the process can be executed concurrently, but also can execute concurrently between multiple threads in one process, so the operating system has better concurrency, which can effectively utilize system resources and improve the throughput of the system. For example, in a single-CPU operating system that does not introduce a thread, if only one file service process is set up when it is blocked for some reason, and no other file service is available to serve, in the operating system that introduces the thread, multiple threads can be set in a file service process, and when the first thread waits, The second thread in the file service process can continue to run; when the second thread blocks the blockade, the third thread can continue to perform, which significantly improves the quality of the file service and the throughput of the system
System overhead
Whether it is the introduction of a threading operating system or a traditional operating system, a process is a separate unit of system resources, and he can have his own resources, and the general thread itself does not own system resources but it can access the resources of the processes it belongs to. That is, the code snippet data segment of one process and system resources are available to all other threads in the same process.
Own resources
Because the system allocates or reclaims resources, such as memory-space I/O devices, when a process is created or revoked, the overhead of the operating system is significantly greater than the cost of creating or revoking the process. Similar to the process switching, it involves the setting of the environment of the entire current process CPU environment and the setting of the CPU environment of the newly scheduled running process, while the thread switching only saves and sets the contents of a few registers, and does not involve the operation of register management. It can be seen that the cost of process switching is much larger than the cost of thread switching, and because multiple threads in the same process have the same address space, the synchronization and communication between them becomes relatively easy, and there is no need for operating system kernel intervention to switch synchronization and communication in some system threads.
This article is from "Shenzhen Lian Cheng Tong technology company" blog, please be sure to keep this source http://roderickkennedy.blog.51cto.com/6758427/1615378
The difference between IOS threads and processes