<?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>Comments on: Is your Singleton Broken?</title>
	<atom:link href="http://fsfoundry.org/codefreak/2006/05/05/is-your-singleton-broken/feed/" rel="self" type="application/rss+xml" />
	<link>http://fsfoundry.org/codefreak/2006/05/05/is-your-singleton-broken/</link>
	<description>Weblog of a lively geek.</description>
	<lastBuildDate>Thu, 04 Mar 2010 10:35:11 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: fr3@K</title>
		<link>http://fsfoundry.org/codefreak/2006/05/05/is-your-singleton-broken/comment-page-1/#comment-5682</link>
		<dc:creator>fr3@K</dc:creator>
		<pubDate>Sun, 26 Apr 2009 08:27:06 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2006/05/05/is-your-singleton-broken/#comment-5682</guid>
		<description>哈哈哈, 謝謝你的提醒. 我的確是蠻屁的, 可是這篇文字沒有對文中提到的任何人或組織 (包括大師在內) 有不敬之意啊.

就像沒有任何現代物理人會否定牛頓的大師地位與貢獻, 但試問如果不正視牛頓力學的狹隘, 要如何才能欣賞相對論的美麗?

另, 本文雖是原創, 但我並不是第一個發表這樣看法的人, 我不過是一個對這些問題點稍有了解並願意將其公開文字化的人. 寫這篇文字的目的是對相關問題提供一篇整合性的中文討論. 當然, 不管是這篇或是站上的其他文字, 若有任何技術上不正確的地方, 還期待您與其他朋友的友善補充指正.

不要想太多了, 還是讓我們回到技術性主題的交流好嗎?</description>
		<content:encoded><![CDATA[<p>哈哈哈, 謝謝你的提醒. 我的確是蠻屁的, 可是這篇文字沒有對文中提到的任何人或組織 (包括大師在內) 有不敬之意啊.</p>
<p>就像沒有任何現代物理人會否定牛頓的大師地位與貢獻, 但試問如果不正視牛頓力學的狹隘, 要如何才能欣賞相對論的美麗?</p>
<p>另, 本文雖是原創, 但我並不是第一個發表這樣看法的人, 我不過是一個對這些問題點稍有了解並願意將其公開文字化的人. 寫這篇文字的目的是對相關問題提供一篇整合性的中文討論. 當然, 不管是這篇或是站上的其他文字, 若有任何技術上不正確的地方, 還期待您與其他朋友的友善補充指正.</p>
<p>不要想太多了, 還是讓我們回到技術性主題的交流好嗎?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fuck</title>
		<link>http://fsfoundry.org/codefreak/2006/05/05/is-your-singleton-broken/comment-page-1/#comment-5641</link>
		<dc:creator>fuck</dc:creator>
		<pubDate>Sat, 25 Apr 2009 02:28:46 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2006/05/05/is-your-singleton-broken/#comment-5641</guid>
		<description>屁的半死的blog...
了不起竟然再批評大師的作品，有種你寫一個來 Open Source Project!

&lt;em&gt;&lt;ul&gt;ed: 不雅無效 url, 已刪除 - fr3@K&lt;/ul&gt;&lt;/em&gt;</description>
		<content:encoded><![CDATA[<p>屁的半死的blog&#8230;<br />
了不起竟然再批評大師的作品，有種你寫一個來 Open Source Project!</p>
<p><em>
<ul>ed: 不雅無效 url, 已刪除 &#8211; fr3@K</ul>
<p></em></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fr3@K</title>
		<link>http://fsfoundry.org/codefreak/2006/05/05/is-your-singleton-broken/comment-page-1/#comment-5025</link>
		<dc:creator>fr3@K</dc:creator>
		<pubDate>Fri, 03 Apr 2009 10:55:10 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2006/05/05/is-your-singleton-broken/#comment-5025</guid>
		<description>好問題. 但我要很不好意思地跟你說 - 我忘記了.

事實上我在後來的 &lt;a href=&quot;http://fsfoundry.org/codefreak/2008/12/29/issues-regarding-global-variable-initialization/&quot; rel=&quot;nofollow&quot;&gt;啟始 Global Variable 的困境&lt;/a&gt; 中寫的 sample code 就是直接用 init() 對 global/singleton 初始化.

看到你的留言後我 revisit 了這段 code, 沒有看出 init_impl() 的必要性. 先讓我以 &quot;它是沒有必要的&quot; 來回答你. 如果之後我看出想出什麼端倪再留言並 email 給你.

Thanks for your comment.</description>
		<content:encoded><![CDATA[<p>好問題. 但我要很不好意思地跟你說 &#8211; 我忘記了.</p>
<p>事實上我在後來的 <a href="http://fsfoundry.org/codefreak/2008/12/29/issues-regarding-global-variable-initialization/" rel="nofollow">啟始 Global Variable 的困境</a> 中寫的 sample code 就是直接用 init() 對 global/singleton 初始化.</p>
<p>看到你的留言後我 revisit 了這段 code, 沒有看出 init_impl() 的必要性. 先讓我以 &#8220;它是沒有必要的&#8221; 來回答你. 如果之後我看出想出什麼端倪再留言並 email 給你.</p>
<p>Thanks for your comment.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: koldkane</title>
		<link>http://fsfoundry.org/codefreak/2006/05/05/is-your-singleton-broken/comment-page-1/#comment-5024</link>
		<dc:creator>koldkane</dc:creator>
		<pubDate>Fri, 03 Apr 2009 09:48:25 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2006/05/05/is-your-singleton-broken/#comment-5024</guid>
		<description>想請教一下，這個 header based singleton，為什麼要透過一個 init_impl()，而不是直接在 init() 初始化 singleton 就好了呢？

像這樣：

// header file
bool init ();
foo&amp; instance ();
namespace
{
  // The next line would be injected to every object file, those include this header file.
  const bool init__ = init();
}
// source file
foo&amp; instance ()
{
  static foo instance_;
  return instance_;
}
bool init ()
{
  instance()
  return true;;
}</description>
		<content:encoded><![CDATA[<p>想請教一下，這個 header based singleton，為什麼要透過一個 init_impl()，而不是直接在 init() 初始化 singleton 就好了呢？</p>
<p>像這樣：</p>
<p>// header file<br />
bool init ();<br />
foo&amp; instance ();<br />
namespace<br />
{<br />
  // The next line would be injected to every object file, those include this header file.<br />
  const bool init__ = init();<br />
}<br />
// source file<br />
foo&amp; instance ()<br />
{<br />
  static foo instance_;<br />
  return instance_;<br />
}<br />
bool init ()<br />
{<br />
  instance()<br />
  return true;;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fr3@K</title>
		<link>http://fsfoundry.org/codefreak/2006/05/05/is-your-singleton-broken/comment-page-1/#comment-4808</link>
		<dc:creator>fr3@K</dc:creator>
		<pubDate>Tue, 03 Feb 2009 11:59:57 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2006/05/05/is-your-singleton-broken/#comment-4808</guid>
		<description>Hi neooranderson,

Glad to be helpful.

&lt;blockquote&gt;其实作为project来说，大部分情况下GoF Singleton是可以适用的？
因为“static mutex mutex_;”在程序启动时已经完成，除非mutex_本身构建需要很长的时间&lt;/blockquote&gt;
很遺憾, 除非不讓其他的 global instance (含 class/file static) 直接/間接參考到它, 否則用了 static mutex 就不行.

這與建構 mutex 所需的時間無關, 這是 dependency 與啟始順序的問題, 請參考我去年底寫的另一篇文字: &lt;a href=&quot;http://fsfoundry.org/codefreak/2008/12/29/issues-regarding-global-variable-initialization/&quot; rel=&quot;nofollow&quot;&gt;啟始 Global Variable 的困境&lt;/a&gt;

另外, 用在 GoF&#039;s singleton 的 double-checked locking 也已經被證實是失敗的手法, 在多緒程序無法正確保障客戶端參考到的是起始完成的對象. 請參考 &lt;a href=&quot;http://www.nwcpp.org/Downloads/2004/DCLP_notes.pdf&quot; rel=&quot;nofollow&quot;&gt;Meyers 的簡報&lt;/a&gt;.

&lt;blockquote&gt;Codejock Software的Xtreme ToolkitPro v10.0中给出了另外一种实现方法...&lt;/blockquote&gt;
我沒玩過這東西不好評論它的優缺點, 但也不期望它會做的多好. Singleton 手法是為了解決 global variable 的技術問題, 但在我看來 &lt;a href=&quot;http://fsfoundry.org/codefreak/2008/12/14/evil-globals-root-from-bad-designs/&quot; rel=&quot;nofollow&quot;&gt;global variable 更是一個設計問題&lt;/a&gt;. 用技術來 work around 糟糕的設計... 你說會是容易的事情嗎?</description>
		<content:encoded><![CDATA[<p>Hi neooranderson,</p>
<p>Glad to be helpful.</p>
<blockquote><p>其实作为project来说，大部分情况下GoF Singleton是可以适用的？<br />
因为“static mutex mutex_;”在程序启动时已经完成，除非mutex_本身构建需要很长的时间</p></blockquote>
<p>很遺憾, 除非不讓其他的 global instance (含 class/file static) 直接/間接參考到它, 否則用了 static mutex 就不行.</p>
<p>這與建構 mutex 所需的時間無關, 這是 dependency 與啟始順序的問題, 請參考我去年底寫的另一篇文字: <a href="http://fsfoundry.org/codefreak/2008/12/29/issues-regarding-global-variable-initialization/" rel="nofollow">啟始 Global Variable 的困境</a></p>
<p>另外, 用在 GoF&#8217;s singleton 的 double-checked locking 也已經被證實是失敗的手法, 在多緒程序無法正確保障客戶端參考到的是起始完成的對象. 請參考 <a href="http://www.nwcpp.org/Downloads/2004/DCLP_notes.pdf" rel="nofollow">Meyers 的簡報</a>.</p>
<blockquote><p>Codejock Software的Xtreme ToolkitPro v10.0中给出了另外一种实现方法&#8230;</p></blockquote>
<p>我沒玩過這東西不好評論它的優缺點, 但也不期望它會做的多好. Singleton 手法是為了解決 global variable 的技術問題, 但在我看來 <a href="http://fsfoundry.org/codefreak/2008/12/14/evil-globals-root-from-bad-designs/" rel="nofollow">global variable 更是一個設計問題</a>. 用技術來 work around 糟糕的設計&#8230; 你說會是容易的事情嗎?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: neooranderson</title>
		<link>http://fsfoundry.org/codefreak/2006/05/05/is-your-singleton-broken/comment-page-1/#comment-4807</link>
		<dc:creator>neooranderson</dc:creator>
		<pubDate>Tue, 03 Feb 2009 10:33:08 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2006/05/05/is-your-singleton-broken/#comment-4807</guid>
		<description>非常有意思，受教了。
其实作为project来说，大部分情况下GoF Singleton是可以适用的？
因为“static mutex mutex_;”在程序启动时已经完成，除非mutex_本身构建需要很长的时间

另外：
Codejock Software的Xtreme ToolkitPro v10.0中给出了另外一种实现方法，在foo类中，定义了foo类静态指针及一个私有类（垃圾收集器），并定义了该类的静态全局变量（static global variable），并在类的析构函数中析构foo的静态指针</description>
		<content:encoded><![CDATA[<p>非常有意思，受教了。<br />
其实作为project来说，大部分情况下GoF Singleton是可以适用的？<br />
因为“static mutex mutex_;”在程序启动时已经完成，除非mutex_本身构建需要很长的时间</p>
<p>另外：<br />
Codejock Software的Xtreme ToolkitPro v10.0中给出了另外一种实现方法，在foo类中，定义了foo类静态指针及一个私有类（垃圾收集器），并定义了该类的静态全局变量（static global variable），并在类的析构函数中析构foo的静态指针</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: COdE fr3@K</title>
		<link>http://fsfoundry.org/codefreak/2006/05/05/is-your-singleton-broken/comment-page-1/#comment-4063</link>
		<dc:creator>COdE fr3@K</dc:creator>
		<pubDate>Thu, 13 Dec 2007 05:33:42 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2006/05/05/is-your-singleton-broken/#comment-4063</guid>
		<description>&lt;strong&gt;拒絕 Singleton...&lt;/strong&gt;

去年我寫過一篇文章, 大意是在說 大多數人所使用的 Singleton 實作都是有問題的.  在文章靠近後面的部份, 我也介紹了一種較少為人知, 我常用在 lifetime 是全局但 scope 是局部的 (global) 變數的 Si...</description>
		<content:encoded><![CDATA[<p><strong>拒絕 Singleton&#8230;</strong></p>
<p>去年我寫過一篇文章, 大意是在說 大多數人所使用的 Singleton 實作都是有問題的.  在文章靠近後面的部份, 我也介紹了一種較少為人知, 我常用在 lifetime 是全局但 scope 是局部的 (global) 變數的 Si&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 今日連結 (2006-09-21) [JeffHung.Blog]</title>
		<link>http://fsfoundry.org/codefreak/2006/05/05/is-your-singleton-broken/comment-page-1/#comment-78</link>
		<dc:creator>今日連結 (2006-09-21) [JeffHung.Blog]</dc:creator>
		<pubDate>Fri, 22 Sep 2006 01:26:09 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2006/05/05/is-your-singleton-broken/#comment-78</guid>
		<description>[...] Is your Singleton Broken? - 解說各種 C++ singleton 的解法，各有優缺點。之前我曾經為了 Xerces-C2 與 Xalan-C 的初始化問題，被逼得也要搞一個 library 用的 singleton 機制[1]，盡可能的僅利用語言機制解決，兩者之間的 dependency，以及多 DLL 混合的程式環境，使得問題更加的複雜。 [...]</description>
		<content:encoded><![CDATA[<p>[...] Is your Singleton Broken? &#8211; 解說各種 C++ singleton 的解法，各有優缺點。之前我曾經為了 Xerces-C2 與 Xalan-C 的初始化問題，被逼得也要搞一個 library 用的 singleton 機制[1]，盡可能的僅利用語言機制解決，兩者之間的 dependency，以及多 DLL 混合的程式環境，使得問題更加的複雜。 [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
