How to correctly use sync.Cond?

前端 未结 8 811
忘了有多久
忘了有多久 2021-02-01 16:11

I\'m having trouble figuring out how to correctly use sync.Cond. From what I can tell, a race condition exists between locking the Locker and invoking the condition\'s Wait meth

8条回答
  •  南方客
    南方客 (楼主)
    2021-02-01 17:00

    Looks like you c.Wait for Broadcast which would never happens with your time intervals. With

    time.Sleep(3 * time.Second) //Broadcast after any Wait for it
    c.Broadcast()
    

    your snippet seems to work http://play.golang.org/p/OE8aP4i6gY .Or am I missing something that you try to achive?

提交回复
热议问题