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{}
}
Golang synchronizes multiple goroutines via channels and sync packages to prevent multiple goroutines from competing for data.
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…
The essence of IO operations is the mutual copying of user space buffers and kernel space buffers.
It generally consists of two steps:
In Linux, the objects of IO are files (because everything is a file).
IO for normal files involves DMA, disk and CPU. For socket files sendfile technology is also included.
From the point of view…
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.
GitHub officially recommends the use of HTTPS URLs, because this method is more applicable (even in the case…
Train for gains