[Go language practice] 8 Concurrency (basic)

Main contents: Run the program using goroutineDetect and correct competition statusUsing channels to share data 1. Concurrency basis 1.1 concurrency and parallelism Concurrency and parallelism are two different concepts: Parallelism means that programs run simultaneously at any time;Concurrency means that programs run simultaneously in ...

Posted by edzulis on Mon, 31 Jan 2022 23:28:19 +0100

Go language Bible - Chapter 8 Goroutines and Channels - 8.5 concurrent loops

Chapter 8 Goroutines and Channels Concurrent programs in Go language can be implemented by two means: goroutine and channel, which support sequential communication processes, or CSP for short. CSP is a concurrent programming model. In this concurrent programming model, values will be passed in different running instances. The second means is m ...

Posted by straycat on Wed, 12 Jan 2022 19:11:13 +0100

A simple for cycle will also step on the pit

prefaceWhen a business is implemented recently, the data needs to be read and then processed asynchronously; Naturally, it is relatively simple to implement in Go. The pseudo code is as follows: list := []*Demo{{"a"}, {"b"}} for _, v := range list { go func() { fmt.Println("name="+v.Name) }() } ty ...

Posted by The_Black_Knight on Mon, 03 Jan 2022 12:22:19 +0100

Read the usage scenario of Go anonymous structure

prefaceAnonymous behavior is very common in go language, such as:Anonymous function: that is, what we know as closureAnonymous fields in structureAnonymous structuresThe design of anonymous behavior brings some difficulties in understanding, but after you are familiar with the use of anonymous design, you will find that anonymous design can hel ...

Posted by Paul Moran on Sat, 11 Dec 2021 10:03:02 +0100