golang条件变量的操作演示

var cond *sync.Cond
func condjob() {
	for {
		cond.L.Lock()

		fmt.Println("condJob ...")
		cond.Wait()
		fmt.Println("condJob ... Done")
		
		cond.L.Unlock()
	}
}

func main() {
	cond = sync.NewCond(&sync.Mutex{})
	go condjob()
	cnt := 0
	for cnt < 4 {
		cnt++
		cond.Signal()
		time.Sleep(time.Second)
	}
}

你可能感兴趣的:(golang,c++,算法)