func f1() { l.RLock()//lock 1 defer l.RUnlock() // //2.thread_b()获取写 写必须等待lock 1释放 l.RLock() //这里又申请读 读 必须等待 thread_b()写锁释放 而thread_b等待该线程释放锁 defer l.RUnlock() } func thread_b() { l.Lock() defer l.Unlock() //等待 lock 1释放 }
func f1() { l.RLock()//lock 1 defer l.RUnlock() // //2.thread_b()获取写 写必须等待lock 1释放 l.RLock() //这里又申请读 读 必须等待 thread_b()写锁释放 而thread_b等待该线程释放锁 defer l.RUnlock() } func thread_b() { l.Lock() defer l.Unlock() //等待 lock 1释放 }