<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>《论golang Timer Reset方法使用的正确姿势》的评论</title>
	<atom:link href="http://tonybai.com/2016/12/21/how-to-use-timer-reset-in-golang-correctly/feed/" rel="self" type="application/rss+xml" />
	<link>https://tonybai.com/2016/12/21/how-to-use-timer-reset-in-golang-correctly/</link>
	<description>一个程序员的心路历程</description>
	<lastBuildDate>Wed, 25 Mar 2026 09:21:20 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>作者：bigwhite</title>
		<link>https://tonybai.com/2016/12/21/how-to-use-timer-reset-in-golang-correctly/#comment-7620</link>
		<dc:creator>bigwhite</dc:creator>
		<pubDate>Fri, 13 May 2022 21:55:42 +0000</pubDate>
		<guid isPermaLink="false">http://tonybai.com/?p=2092#comment-7620</guid>
		<description>用len(timeout.C)判断C中是否有值这个操作与另外一个goroutine drain channel的操作依然存在竞态，是不准确的。你的代码存在阻塞在&lt;-timeout.C上的可能。</description>
		<content:encoded><![CDATA[<p>用len(timeout.C)判断C中是否有值这个操作与另外一个goroutine drain channel的操作依然存在竞态，是不准确的。你的代码存在阻塞在&lt;-timeout.C上的可能。</p>
]]></content:encoded>
	</item>
	<item>
		<title>作者：mht</title>
		<link>https://tonybai.com/2016/12/21/how-to-use-timer-reset-in-golang-correctly/#comment-7619</link>
		<dc:creator>mht</dc:creator>
		<pubDate>Fri, 13 May 2022 14:29:32 +0000</pubDate>
		<guid isPermaLink="false">http://tonybai.com/?p=2092#comment-7619</guid>
		<description>if !timeout.Stop() &amp;&amp; len(timeout.C) &gt; 0 {
  &lt;-timeout.C
}
这样可以吗</description>
		<content:encoded><![CDATA[<p>if !timeout.Stop() &amp;&amp; len(timeout.C) &gt; 0 {<br />
  &lt;-timeout.C<br />
}<br />
这样可以吗</p>
]]></content:encoded>
	</item>
	<item>
		<title>作者：progrequest</title>
		<link>https://tonybai.com/2016/12/21/how-to-use-timer-reset-in-golang-correctly/#comment-7560</link>
		<dc:creator>progrequest</dc:creator>
		<pubDate>Sat, 07 Aug 2021 03:10:54 +0000</pubDate>
		<guid isPermaLink="false">http://tonybai.com/?p=2092#comment-7560</guid>
		<description>@lion drain channel 和 read timer.C 之间没有竞争关系，但是drain channel的判断条件有，调用Drain Channel的条件是通过Stop()得到的，但是Stop()和sendTime之间不是互斥的（博主明确说明了f()的调用没有加锁）。</description>
		<content:encoded><![CDATA[<p>@lion drain channel 和 read timer.C 之间没有竞争关系，但是drain channel的判断条件有，调用Drain Channel的条件是通过Stop()得到的，但是Stop()和sendTime之间不是互斥的（博主明确说明了f()的调用没有加锁）。</p>
]]></content:encoded>
	</item>
	<item>
		<title>作者：stemon</title>
		<link>https://tonybai.com/2016/12/21/how-to-use-timer-reset-in-golang-correctly/#comment-7554</link>
		<dc:creator>stemon</dc:creator>
		<pubDate>Fri, 18 Jun 2021 09:16:40 +0000</pubDate>
		<guid isPermaLink="false">http://tonybai.com/?p=2092#comment-7554</guid>
		<description>为什么不这样呢：
timeout := time.NewTimer(T)
for {
    timeout.Reset(T)

    select {
    case &lt;- ...: ...
        if !timeout.Stop() {
            &lt;-timeout.C
        }
    case &lt;-timeout.C: ...
    }
}</description>
		<content:encoded><![CDATA[<p>为什么不这样呢：<br />
timeout := time.NewTimer(T)<br />
for {<br />
    timeout.Reset(T)</p>
<p>    select {<br />
    case &lt;- &#8230;: &#8230;<br />
        if !timeout.Stop() {<br />
            &lt;-timeout.C<br />
        }<br />
    case &lt;-timeout.C: &#8230;<br />
    }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>作者：bglmmz</title>
		<link>https://tonybai.com/2016/12/21/how-to-use-timer-reset-in-golang-correctly/#comment-7314</link>
		<dc:creator>bglmmz</dc:creator>
		<pubDate>Thu, 03 Jan 2019 10:04:32 +0000</pubDate>
		<guid isPermaLink="false">http://tonybai.com/?p=2092#comment-7314</guid>
		<description>的确，在example 4 会发生#11513的issue。</description>
		<content:encoded><![CDATA[<p>的确，在example 4 会发生#11513的issue。</p>
]]></content:encoded>
	</item>
	<item>
		<title>作者：lion</title>
		<link>https://tonybai.com/2016/12/21/how-to-use-timer-reset-in-golang-correctly/#comment-7271</link>
		<dc:creator>lion</dc:creator>
		<pubDate>Fri, 21 Sep 2018 02:07:50 +0000</pubDate>
		<guid isPermaLink="false">http://tonybai.com/?p=2092#comment-7271</guid>
		<description>确实好文,学习了不少。但是在example 4 个人感觉方案可行。其中“这时候timer expire过程中sendTime的执行与“drain channel”是分别在两个goroutine中执行的，谁先谁后，完全依靠runtime调度”我觉得理解有问题，在drain channel goroutine阻塞在&lt;-timer.C这，并没有和sendTime有竞争关系。</description>
		<content:encoded><![CDATA[<p>确实好文,学习了不少。但是在example 4 个人感觉方案可行。其中“这时候timer expire过程中sendTime的执行与“drain channel”是分别在两个goroutine中执行的，谁先谁后，完全依靠runtime调度”我觉得理解有问题，在drain channel goroutine阻塞在&lt;-timer.C这，并没有和sendTime有竞争关系。</p>
]]></content:encoded>
	</item>
	<item>
		<title>作者：Samuel</title>
		<link>https://tonybai.com/2016/12/21/how-to-use-timer-reset-in-golang-correctly/#comment-7155</link>
		<dc:creator>Samuel</dc:creator>
		<pubDate>Thu, 22 Mar 2018 15:44:46 +0000</pubDate>
		<guid isPermaLink="false">http://tonybai.com/?p=2092#comment-7155</guid>
		<description>好文，受教了～</description>
		<content:encoded><![CDATA[<p>好文，受教了～</p>
]]></content:encoded>
	</item>
	<item>
		<title>作者：幸福蛋</title>
		<link>https://tonybai.com/2016/12/21/how-to-use-timer-reset-in-golang-correctly/#comment-4577</link>
		<dc:creator>幸福蛋</dc:creator>
		<pubDate>Fri, 02 Jun 2017 08:34:41 +0000</pubDate>
		<guid isPermaLink="false">http://tonybai.com/?p=2092#comment-4577</guid>
		<description>你好，TCP长连接中，作为心跳包超时，我对每个连接是使用conn.SetReadDeadline()这个方法好，还是全局一个time wheel来维护所有的连接好？</description>
		<content:encoded><![CDATA[<p>你好，TCP长连接中，作为心跳包超时，我对每个连接是使用conn.SetReadDeadline()这个方法好，还是全局一个time wheel来维护所有的连接好？</p>
]]></content:encoded>
	</item>
</channel>
</rss>
