A preliminary understanding of parallel in Go

Source: Internet
Author: User

Introduction to some concepts:

Concept Describe
Process

In-memory programs. Has its own independent exclusive virtual CPU, virtual Memory, virtual IO devices.

(1) Each process occupies a separate address space. The address space here includes code, data, and other resources.
(2) communication overhead between processes is large and subject to many constraints. Object (or function) interface, communication protocol
(3) The switching overhead between processes is also large. Also known as context Switch. The context includes code, data, stacks, processor state, and resources.

Thread

Lightweight process. In modern operating systems, it is the smallest unit of program execution flow in a process. A standard thread consists of a thread ID, a current instruction pointer (PC), a collection of registers, and a stack.

(1) Multiple threads share the address space of a process (code, data, other resources, and so on).
Threads also need their own resources, such as program counters, register groups, call stacks, and so on.

(2) communication overhead between threads is less and simpler.
Because sharing reduces the content that needs to be communicated.
However, shared resources cannot be protected because they are fully shared.

(3) The switching overhead between threads is also small.
Just save the program counters, register groups, stacks, and so on for each thread.
No need to switch or copy the entire address space, resulting in a much lower cost (about 1/10)

Co-process Lightweight threads. is a function that can be executed concurrently, by a compile or user-specified location, giving control to the way the scheduler executes. It is non-preemptive, avoids repeated system calls, and the overhead of process switching, giving you thousands of logical streams, also known as user-level threads.
Logical processor Each logical processor binds to a thread and is responsible for the execution of the Goroutine
Concurrent Concurrency is based on the time period of the dimension, that is, in the unit time, while accomplishing many things.
Parallel Parallelism is a point-in-time dimension, that is, at some point in time, accomplishing multiple things simultaneously.

A preliminary understanding of parallel in Go

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.