What is the underlying structure of Golang Channel
This article mainly introduces the relevant knowledge of "what is the underlying structure of Golang Channel". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "what is the underlying structure of Golang Channel" can help you solve the problem.
Golang implements the CSP (Communicating Sequential Processes) model using Groutine and channels, and channles plays an important role in the communication and synchronization of goroutine.
In GopherCon 2017, Golang expert Kavya deeply introduces the internal mechanism of Go Channels and how the runtime scheduler and memory management system support Channel. This paper studies and analyzes the principle of go channels according to Kavya's ppt, hoping to bring some inspiration for the correct and efficient use of golang concurrency in the future.
Start with a simple channel application, using goroutine and channel to implement a task queue that processes multiple tasks in parallel.
Func main () {/ / buffered channel ch: = make (chan Task, 3) / start a fixed number of worker for i: = 0; I < numWorkers; iTunes + {go worker (ch)} / / send the task to worker hellaTasks: = getTaks () for _, task: = range hellaTasks {ch