Image for post
Image for post
this pic from gopher conf 2020

When a goroutine can start other goroutines, and those goroutines start other goroutines, and so on, then the first goroutine should be able to send cancellation signals to all embedded goroutines.

The sole purpose of the context package is to perform cancellation signals between goroutines, regardless of how they were generated.

The interface of the Context is defined as:

type Context interface {
Deadline() (deadline time.Time, ok bool)
Done() <- chan struct{}
Err() error
Value(key interface{}) interface{}
}
  • Deadline: The first value is the deadline, at which point the Context will automatically trigger the Cancel action. The second value is a boolean value, true means the deadline is set, false means the deadline is not set. …


Image for post
Image for post
this pic from https://twitter.com/phanor/status/932083816059101184

Golang synchronizes multiple goroutines via channels and sync packages to prevent multiple goroutines from competing for data.

Data competition problem

Due to the data competition problem, it is necessary to synchronize multiple goroutines concurrently, so we need to understand what data competition is before that.

To understand data competition, it is necessary to mention atomic operations.

When each task executed by the computer cannot be further subdivided (it cannot be split into smaller subtasks), it is an atomic task.

Atomic operations are operations that are directly implemented by a single CPU instruction (this instruction cannot be interrupted during execution).

Usually, num = num + 1 looks like a single line of code, but it actually adds num to 1 and then writes num, which is not an atomic operation since there are two instructions after compilation. …


Image for post
Image for post
this pic from Google I/O 2020 news

In the world of hardware and software, IO is everywhere.

A computer can be thought of as a series of IO devices connected by a bus. Even a bus can be considered as an IO device. The basic way of working of these hardware is: input data -> process data -> output data. They differ only in the way they handle data.

The same is true for software, where data can be static (e.g. constants), from local disks, or from remote processes (e.g. the internet). …


Image for post
Image for post

As we all know, Linux is a multitasking operating system that supports a much larger number of CPUs running at the same time. Of course, these tasks are not really running at the same time, but rather because the system allocates the CPU to them in turn in a very short period of time, creating the illusion of multiple tasks running at the same time.

Before running each task, the CPU needs to know where to load it and where to start running it, i.e., the CPU registers and program counters need to be set for it in advance.

What is CPU context?

The basic cycle of every CPU is to fetch the first instruction from memory, decode it to determine its type and operands, execute it, and then fetch, decode, and execute subsequent instructions. The cycle is repeated until the program finishes. In this way, programs are carried out. …


Image for post
Image for post

Everything we found says that TCP is a connection-oriented service and that all applications that communicate over TCP must first establish a connection before they can communicate, and then remember to close the connection after they have done so.

But what is the TCP connection itself?

Conclusion

To conclude, the connection is actually a data structure in the operating system kernel called the TCP control block (TCB), or in linux, the tcp_sock structure. Not only the connection, but also the packets are controlled by a data structure known as the sk_buff structure in linux.

The state of TCP corresponds to the state of the TCP…


Image for post
Image for post

When the local computer communicates with GitHub, the transmission is mainly based on two protocols, HTTPS and SSH, and the corresponding repository addresses are HTTPS URLs and SSH URLs.

The first thing to emphasize is that HTTPS URLs and SSH URLs correspond to two completely independent permission verification methods. The main difference is that HTTPS URLs use account passwords for verification, and SSH URLs use SSH key pairs for verification. In normal use, we can choose one according to the actual situation.

HTTPS URLs

GitHub officially recommends the use of HTTPS URLs, because this method is more applicable (even in the case of a firewall or proxy), and is more convenient to use (easier configuration). …


Image for post
Image for post

In most OSs, usually different versions of the same software can exist at the same time, and they usually exist in different locations.

For example (macOS):

About

Will Chu

Train for gains

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store