## 线程同步
```
import ("sync")
var mu sync.Mutex // 互斥锁,
var mu sync.RWMutex 读写锁
```
### 互斥锁
```
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
var lock sync.Mutex
func main() {
m := map[string]int{"a":1, "b":2}
for i := 0; i <= 3; i ++ {
go func(a map[string]int) {
lock.Lock()
a["a"] = rand.Int()
lock.Unlock()
}(m)
time.Sleep(time.Second)
}
lock.Lock()
fmt.Println(m)
lock.Unlock()
time.Sleep(5 * time.Second)
}
```
### 读写锁
场景:读多写少