<story><title>Singleton Pattern in Go</title><url>http://marcio.io/2015/07/singleton-pattern-in-go/</url></story><parent_chain></parent_chain><comment><author>colin_mccabe</author><text>It&amp;#x27;s funny how you can take an obvious antipattern (global variables) and turn it into a pattern by giving it a cool new name like &amp;quot;Singleton&amp;quot;.  In this spirit, I propose &amp;quot;the ProgramCounterAmbulator&amp;quot; as a cool new name for &amp;quot;goto.&amp;quot;&lt;p&gt;Actually, gotos are usually less harmful than globals.  At least they don&amp;#x27;t interfere with unit testing the way globals tend to.</text></comment>
<story><title>Singleton Pattern in Go</title><url>http://marcio.io/2015/07/singleton-pattern-in-go/</url></story><parent_chain></parent_chain><comment><author>pcwalton</author><text>Your &amp;quot;check-lock-check&amp;quot; code is probably broken (depending on the intricacies of Golang&amp;#x27;s memory model). If the compiler or CPU reorders any stores to the fields of &amp;quot;instance&amp;quot; after the assignment to &amp;quot;instance&amp;quot; itself, other threads could start working with a partially uninitialized object. Once() uses atomics on the fast path for a reason.</text></comment>