Traditional Culture Encyclopedia - Traditional festivals - What is the difference between a process and a thread? Which is more efficient and why?
What is the difference between a process and a thread? Which is more efficient and why?
It is the execution unit of the process and the scheduling entity of internal medicine in the process. A basic unit that runs independently and is smaller than a process. Threads are also called lightweight processes.
A program has at least one process and a process has at least one thread.
Qq and WeChat are both processes, and the chat, qq space and attention in qq are all threads.
Each process has its own address space, that is, process space. Under the network or multi-user switching, a server usually needs to receive a large number of concurrent requests from an uncertain number of users. It is obviously not feasible to create a process for each request (high system overhead and low efficiency in responding to user requests), so the concept of thread is introduced into the operating system.
The execution process of the 1. thread is linear. Although there will be interruptions or pauses, the resources owned by the process only serve the linear execution process. These resources need to be protected once the threads are switched.
2. Processes are divided into single-threaded processes and multi-threaded processes. Single-threaded process is also a linear execution process from a macro perspective, and there is only one execution process from a micro perspective. Multi-threaded processes are linear on the macro level and perform multiple operations on the micro level.
The change of thread only represents the change of the execution process of CPU, and there is no change of the resources owned by the process.
Process switching, resource consumption and high efficiency. So when frequent switching is needed, it is better to use threads than processes. Similarly, if you need to manipulate some variables at the same time, you can only use threads instead of processes.
Thread execution overhead is small, but it is not conducive to the management and protection of resources. Threads are suitable for running on SMP machines (dual CPU systems).
Process execution costs a lot, but it can manage and protect resources well. The process can move forward across the machine.
- Previous article:Binyang, Guangxi where there is handmade work outsourcing
- Next article:Chinese and Western cultural differences to explore the sense of
- Related articles
- Explain the working principle of refrigerator compressor in detail, so that users can become experts.
- How about Hubei Changyuan Agricultural Products Storage Logistics Co., Ltd.?
- Excuse me, Amway, is there any special food in your hometown?
- What are the two main management methods of traditional e-commerce process?
- How to play the long card that Sichuan people like?
- Jasmine tea tea ceremony copywriting
- The traditional festivals in China are arranged in order.
- Top Ten Attractions in Guangzhou
- How much do you charge for binding and printing books in Beijing?
- Six Handmade Works by Grade Two Students