Go channels and locks

How to communicate between different goroutines? There are two options:

1. Mutex of global variables

2. Use pipeline channel to solve

Because there is no lock on the global variable m, there will be a resource contention problem, and an error will occur in the code, prompting concurrent map writes

 var (     myMap = make(map[int]int, 10)     lock sync.Mutex )  func test(n int) {     res := 1     for i := 1; i <= n; i++ {         

The post Go channel with locks first appeared on Lenix Blog .

This article is reprinted from https://blog.p2hp.com/archives/9098
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment