In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "how to understand processes, threads, and collaborations". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Process
A process is the smallest unit of resources allocated by the operating system, that is, each program we write contains at least one process and, of course, multiple processes. In the process, we have our own resource management, we can apply for memory, we can carry out data operations, these are all things that the process needs to deal with.
Thread
If you have a process, why do you need threads? Because process switching consumes too much resources. We know that the emergence of a thing or a method must be to solve some problem or some problem. The emergence of threads is to facilitate operating system scheduling, so threads are the smallest unit of operating system scheduling. There can be one thread or multiple threads in a process, and multiple threads do their own things to each other, but they share the storage space of the process, that is to say, they can all access the memory space of the process. The advantage is that it is convenient for threads to communicate, and the disadvantage is obvious. If multiple threads want to modify the data of shared memory at the same time, they will compete. The lock mechanism is a way to solve the problem of modifying shared memory between threads with shared memory.
CTRIP
The creation of the process needs the most resources, and the thread needs much less resources than it, but people still seem to be dissatisfied, so the cooperative program is born, and it needs less resources, only a few kb, that is to say, an ordinary host can easily start hundreds of thousands of collaborations. As we said before, the process is the smallest unit of resource allocation for cpu, and the thread is the smallest unit of cpu management, so how does the cpu manage the co-program? The answer is that the operating system cpu does not manage the protocol directly, but by the user, so we often call it user-mode threads.
Since co-programs are managed by users, we can switch between different co-programs according to our needs. For example, when a co-program encounters io time-consuming operations, we can switch cpu resources to other co-programs, so that we can greatly improve cpu utilization.
Although the cooperative program is very convenient, because it is necessary for the user to manage the state switching, the user needs to implement a processor scheduling mechanism, which is not simple, which is why it is known that many languages have implemented the cooperative program recently.
Summary
Whether it is a process, thread or co-program, they are all a resource block and a block of code that can be dispatched by cpu. The difference is how cpu schedules them. The operating system handles the scheduling of cpu through the management of processes and threads. The operating system encapsulates the implementation of processes and threads. All we need to do is to make our programs allocate processor resources as reasonably as possible.
When we understand this, we pay more attention to how to communicate between processes, between threads and processes, and between collaborators, which are actually what we pay more attention to in the coding process.
This is the end of the content of "how to understand processes, threads, collaborations". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.