About threads, processes, and co-routines

Source: Internet
Author: User

A process is a program with a certain set of independent functions on a data collection of a running activity, the process is a system for resource allocation and scheduling of a separate unit, each process has its own independent memory space, different processes through interprocess communication to communicate. Because of the process weight, occupy the independent memory, so the switching overhead between the context process (stack, register, virtual memory, file handle, etc.) is relatively large, but relatively safe and stable.

A thread is an entity of a process, a succession unit of CPU dispatch and dispatch, which is a smaller unit that can run independently than a process, and the thread itself does not own system resources, but has only a few resources (such as program counters, a set of registers and stacks) that are essential to the operation. However, it can share all of the resources owned by the process with other threads that belong to one process. Inter-thread communication mainly through shared memory, context switching, resource overhead is less, but compared to the process, not stable enough, easy to lose data.

The process is a kind of user-state lightweight thread, the scheduling of the association is completely user-controlled. The co-process has its own register context and stack. When the scheduling switch, the register context and the stack is saved to another place, in the cut back, the recovery of the saved register context and stack, the direct Operation Stack is basically no kernel switching overhead, can not lock the access to global variables, so the context of the switch is very fast.

About threads, processes, and co-routines

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.