Golang 互斥锁与读写锁
互斥锁 代码示例 package main import ( "fmt" "sync" "time" ) func main() { //声明 var mutex sync.Mutex fmt.Println("Lock the lock. (G0)") //加锁mutex mutex.Lock() fmt.Println("The lock is locked.(G0)") for i := 1; i < 4; i++ { go func(i int) { fmt.Printf("----Lock the lock. (G%d)\n", i) mutex.Lock() fmt.Printf("++++The lock is locked. (G%d)\n", i) }(i) } //休息一...阅读全文