This is the first day of my participation in Gwen Challenge
Why does Go design concurrency based on CSP theory?
Over the years, concurrent design and multithreaded programming have become synonymous with complexity. We think this is partly due to complex designs such as Pthreads, and partly due to over-emphasis on minimal detail such as mutex, conditional parameters, and memory barriers. But if you design a higher-level interface, you might still have mutex designs inside, but hide them and make programming easier.
Communicating Sequential Processes (CSP) is one of the most successful language concurrent designs. Occam and Erlang, two famous languages, are derived from CSP. Go’s concurrent design philosophy stems from the design of a channel. Some early languages tried to design CSP, which proved that the CSP model is very suitable for procedural framework languages.
Why does Go not assert?
Go does not provide assertions. Assertions are undeniably convenient. But in our experience, programmers often abuse assertions because they don’t want to think about how best to handle exceptions. Better exception handling means that when a service encounters a non-fatal error, it continues to run. Precise error types allow programmers to locate errors more quickly.
We know this is a controversial point, and there are many, many differences between Go and other modern languages, but also because we think these designs are worth experimenting with.
Why does Go use coroutines instead of threads?
Gorountine makes concurrent programming easy. This design allows the program to multichannel on a series of threads when a coroutine blocks, for example by executing a system-blocking command. The “run-time” system Runtime automatically moves other coroutines to another runnable thread from a thread in the same system state so that they do not block. These details are invisible to the programmer, which is crucial. We can perform a coroutine very cheaply. It costs no more than a stack of space.
To make the stack smaller, Go runs on a scalable (but capped) stack. A newly built coroutine starts with a few kilobytes, which is almost enough to fit on a stack. The go runtime automatically expands the stack to accommodate more coroutines if it runs short. Each function call costs only three low-cost instructions.
It is easy to create hundreds or thousands of coroutines at the same memory address, whereas with threads, the same number of system resources can be consumed quickly.
Overhead N. Multiplex mint n. Modest n. Instruction NCopy the code
Stem from primitive old derive from derivation, exploration, notion proceduralCopy the code