GO并发相关
锁的使用
注意要成对,重点是代码中有分支或者异常返回的情况,这种情况要在异常返回前先释放锁
mysqlInstanceLock.Lock() slaveHostSql := "show slave hosts" ss1 := dc.SqlRes(DcServer, ip, port, msdb.DbName, slaveHostSql,false , common.AdminMysqlUserName, common.AdminMysqlPassword) if ss1 == "" { //has not slave hosts; mysqlInstanceLock.Unlock() return } mysqlInstanceLock.Unlock()