process
The basic unit in which concurrent programs allocate and manage resources during execution. It is a dynamic concept that competes with the basic unit of computer system resources. An application that runs in memory. Each process has its own independent memory space. A process can have multiple threads. For example, in Windows, a running XX. exe is a process.
thread
An execution task (control unit) in a process that is responsible for the execution of programs in the current process. A process has at least one thread. A process can run multiple threads, and multiple threads can share data. A basic unit smaller than a process that runs independently. Threads are also called lightweight processes.
Unlike the process heap of similar process are Shared by multiple threads and method of area resources, but each thread has its own program counter, the virtual machine and the local method stack, so the system in one thread, or switch between individual threads, burden is much smaller than the process, also because of this, thread, also known as a lightweight process.
coroutines
Is a more lightweight existence than threads. A thread can also have more than one coroutine. Its execution is more like a subroutine, or a function call with no return value.
Summary of the differences between processes and threads
Basic difference: process is the basic unit of operating system resource allocation, while thread is the basic unit of processor task scheduling and execution resource overhead: each process has independent code and data space (program context), switching between programs will have a large overhead; Threads can be regarded as lightweight processes. The same type of threads share code and data space, and each thread has its own independent running stack and program counter (PC). Switching between threads has little overhead. Inclusion: If there are multiple threads in a process, the execution process is not one line, but multiple lines (threads). Threads are part of a process, so they are also called lightweight or lightweight processes. Memory allocation: Threads of the same process share the address space and resources of the process, and the address space and resources between processes are independent of each other: each independent process has the entry of program execution, sequential execution sequence and program exit. However, threads cannot be executed independently and must be dependent on the application, which provides control over the execution of multiple threads, both of which can be executed concurrently
Coroutines and threads
Threads are relatively independent and have their own context switches controlled by the system
Coroutines are relatively independent and have their own context switching controlled by themselves, switching from the current coroutine to other coroutines controlled by the current coroutine.