例如 会先获取了读锁,协程里面有个写锁,如果整体还嵌套了读锁,直接出现死锁了 ,卡在all_lock_test.RLock() ,读锁永远也不能释放了
go
package routes
import (
"fmt"
"sync"
"testing"
"time"
)
var all_lock_test sync.RWMutex
func TestSendGiftInfo_SendBlind(t *testing.T) {
if !all_lock_test.TryRLock() {
return
}
defer all_lock_test.RUnlock()
go func() {
all_lock_test.Lock()
defer all_lock_test.Unlock()
fmt.Println("配置更新")
}()
time.Sleep(time.Second)
rDeal()
}
func rDeal() {
all_lock_test.RLock()
defer all_lock_test.RUnlock()
fmt.Println("处理业务完毕")
}