Process/thread

What is in/thread

A process is the smallest unit of resource allocation, and a thread is the smallest unit of CPU scheduling. An application has at least one process, and a process has at least one thread.

Thread private: thread stack, kernel stack, program counter, register

Thread sharing: address space, heap memory (shared variables, static variables)

Process private: address space, heap, stack, register

Process sharing: I know there is a shared memory

Their advantages and disadvantages:

Because threads share the address space of the process, thread switching will not cause the TLB cache to expire, so the cost of thread switching is lower. At the same time, because the creation of a process needs to allocate a lot of resources and create an independent address space for it, and the thread only needs its own stack and registers, etc., the cost of thread creation is also lower.
But because threads share the virtual address space, the degree of isolation between them is smaller, and the crash of one thread may affect other threads. The process will not, so the process is more robust.

Guess you like

Origin blog.csdn.net/qq_41634872/article/details/110203281