Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

关于time.Timer的疑问

image

上图中,当需要reset一个时间的时候,如果这个事件当前已经超时,通道里已经有有数据,则需要先取出数据再进行reset,这个我可以理解,但是如图的实现方法不会导致并发错误么?
比如在if判断的时候条件不成立,然后当前协程被挂起,定时器相关协程执行,刚好这个事件超时,通道里被写入数据。然后当前协程被切回来并reset,但此时通道里已经有数据,导致被立刻唤醒?
如果我的理解有问题的话请问正确实现应该是什么样的


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...