Golang Concurrency II (dispatch)

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed.

Golang Concurrent Two (principle)

Each operating system has a fixed-size stack memory, and the user holds local variables for the function. But this fixed size is obviously less flexible than the empty energy. Instead, Goroutine applies a very small stack at the beginning of the lifecycle, similar to the operating system thread, to hold local variables during function calls. The essential difference is that its size is not fixed and can be enlarged and scaled down as needed.

The operating system thread is dispatched by the kernel, every few seconds, the CPU calls the kernel function, pauses the running thread, saves the execution information to memory, finds the next thread to execute, then resumes execution information from memory, and finally executes the thread. Context switches because the state of a thread is saved to memory and the state of another thread is restored from memory. This is a relatively slow process.

The Go runtime contains a scheduler that can call M goruotine to n operating system threads, unlike operating system thread scheduling, where the go Scheduler is not determined by the clock, but is triggered by a specific go language structure.

Each thread in Java has a unique identity, but Goroutine does not provide an identity that the programmer can access.

Related Article

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.