This is a creation in Article, where the information may have evolved or changed.
1. Operating system and Runtime library
The term "runtime" actually includes not only the library files used to link with the compiled target execution program, but also the operating environment of the scripting language or bytecode-interpreted language, such as the python,c# Clr,java JRE.
Encapsulation of system calls is only a small part of the runtime's functionality, and the runtime typically provides features such as string processing, mathematical calculations, common data structure containers, and so on that do not require operating system support, while the runtime also provides more advanced encapsulation of features supported by the operating system, such as IO with cache and format, The thread pool.
1. Support new semantics or syntax so that we can describe and solve problems. such as Java generics, Annotation, lambda expressions.
2. A new tool or class library has been provided, reducing the amount of code we have developed. For example, Python 2.7 argparse
3. A better and more comprehensive encapsulation of system calls allows us to do things that were impossible or difficult to do before in this language environment. such as Java NIO
2. Concurrency and parallelism (Concurrency and Parallelism)
Concurrency refers to the logical structure of a program. A non-concurrent program has only one logical control flow, which is the sequential Execution (sequential) program.
Parallelism refers to the running state of a program. If a program is processed at the same time by multiple CPU pipelines at a time, then we say that the program is running in parallel.
3. Scheduling of threads
4. Concurrent Programming Framework
5. Goroutine
(1) Goroutine is the function of the go language runtime, not the functionality provided by the operating system, Goroutine is not implemented with threads. Refer to the HTTP://GOLANG.ORG/SRC/PKG/RUNTIME/PROC.C in the Go language source
(2) Goroutine is a piece of code, a function entry, and a stack allocated to it on the heap. So it's very cheap and we can easily create tens of thousands of goroutine, but they're not executed by the operating system.
(3) In addition to a thread that is blocked by the system call, the Go runtime will start up to $gomaxprocs threads to run Goroutine
(4) Goroutine is a cooperative scheduling, if the goroutine will take a long time, and not by waiting to read or write to the channel data to synchronize, you need to actively call gosched () to let the CPU
(5) As in all other concurrent frames, the goroutine advantage of the so-called "no lock" is only valid on a single thread, and if $gomaxprocs > 1 and the co-process need to communicate, the Go runtime is responsible for lock-protected data. This is why sieve.go such an example is slower in multi-CPU multi-Threading
(6) The Web and other service-side programs to deal with the request is essentially a parallel processing problem, each request is basically independent, non-dependent, almost no data interaction, this is not a model of concurrent programming, and the concurrent programming framework only solves the complexity of its semantic expression, not fundamentally improve the efficiency of processing, Perhaps the English of concurrent connections and concurrent programming is concurrent, and it is easy to create a misunderstanding that the concurrent programming framework and coroutine can handle a large number of concurrent connections efficiently.
(7) The Go Language runtime encapsulates asynchronous IO, so it is possible to write a server that looks like a lot of concurrency, but even if we tune $gomaxprocs to take advantage of multi-core CPU parallelism, it is not as efficient as we use IO event-driven design to divide the appropriate proportion of thread pools by transaction type. In response time, collaborative scheduling is flawed.
(8) Goroutine The biggest value is that it realizes the concurrent and actual parallel execution of the thread mapping and dynamic expansion, along with the development and improvement of its running library, its performance will be better, especially in the CPU more and more of the future of the number of cores, One day we will give up the difference in performance for the simplicity and maintainability of the code.