process, thread, correlation interpretation of the association "reprint"

Source: Internet
Author: User

I do not understand this piece, forwarding and everyone share!!!

    1. Process, managed by the OS, each process has its own independent memory space, the communication between processes is mainly through the way of signal transmission to achieve, the implementation of a variety of ways, semaphores, pipelines, events, any one way of communication efficiency is required over the core, resulting in low communication efficiency. Because it is a separate memory space, So the context switch needs to save the information of the yourselves call stack, the information of the CPU registers, the virtual memory, and the open related handle, so the cost of context switching is very high, so the process is not suitable for mass creation.
    2. Threads: also managed by the OS, a process can have multiple threads, but each of these threads shares the resources of the parent process like an OS request, which includes virtual memory, files, and so on, because it is a shared resource, so the system resources required to create the thread are much smaller than the process. The corresponding number of threads that can be created is also a lot more. Thread-time communication can also be communicated through shared memory, in addition to the way communication between processes can be used, a multiple thread in Java can communicate through a shared queue, because it is in memory access, So this speed you can totally imagine is much faster than passing through the kernel. In addition to the scheduling aspect or because the memory is shared, so the context switch needs to save things like the less, so that the context of the switch is also efficient, but there is a situation of context switching efficiency and process switching is similar, That's the switch of time for different thread groups, and you can basically think of a thread group as a process (which, in efficiency, is not)
    3. Co-process: the processes and threads mentioned above are controlled by the OS to switch, using a preemptive (why?). The user level is the east, his switch is determined by the user himself, you can think of the user to create a few threads, Then each thread is looping through the specified task list in order to complete the different tasks, when the task is blocked to perform the next task, when the recovery back to perform this task, the switch between tasks only need to save the context of each task, like a direct operation Stack, so there is no kernel switching overhead , so the context switch is very fast. In addition, the process also needs to ensure that the non-clogging and no interdependence, the process is basically unable to synchronize communication, more use of one-step message communication, high efficiency. The representative is Golang inside Goroutine.

There is also a green thread, which is relatively rare, and the similarity of the association is not controlled by the OS scheduling, but by the user to dispatch him, but his context switch and synchronization are more like threads

Processes, threads, and related interpretations of the association "reprint"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.