What is the connection processes and threads and the difference

A simple example
1. Definition:
1) process is a program with a certain separate functions run on one activity on a data collection system is an independent unit of resource allocation and scheduling.
2) A thread is a physical process, is the basic unit of CPU scheduling and dispatching, he is smaller than the process of the basic unit can operate independently, basically does not own its own thread system resources, with only essential point in the operation resource (such as a program counter, a set of registers and stack), a thread can be created and destroyed another thread;
2. the relationship between processes and threads:
(1) a thread can belong to only one process, and a process can have multiple threads, but there is at least one thread.
(2) the resources allocated to the process, all threads in the same process of sharing all the resources of the process.
(3) threads in the implementation process, the need to work in sync. Between threads of different processes to make use of synchronized way messaging.
(4) points to the thread handling machine, i.e. the real processors running on a thread.
(5) a thread refers to a scheduling entity within the process execution unit, but also the process.
3. The difference between threads and processes:
(1) Scheduling: the thread as a basic unit of scheduling and allocation, process as the basic unit of own resources.
(2) Concurrency: concurrent execution process can not only between but also can execute concurrently across multiple threads of the same process.
(3) have the resources: the process is an independent unit with the resources, the thread does not have the system resources, but can access resources belong to the process.
(4) overhead: when creating or revocation process, due to system resource allocation and deallocation of whom have led to significantly greater than the cost of creating or revoked when the thread system. But the process has a separate address space, the process crashes, will not have an impact on other processes in protected mode, but just different threads of execution paths in a process. Thread has its own stack and local variables, but there is no separate address spaces between the threads, a thread to die is tantamount to the whole process dies, so the program than multi-process multi-threaded programs robust, but in the process of switching, consuming greater resource efficiency to be satisfactory

Published 27 original articles · won praise 3 · Views 717

Guess you like

Origin blog.csdn.net/weixin_43849280/article/details/101622201