<?xml version="1.0" encoding="gb2312"?>
<rss version="2.0">
<channel>
<title><![CDATA[dyerac]]></title>
        <image>
        <title>http://hi.baidu.com</title>
        <link>http://hi.baidu.com</link>
        <url>http://img.baidu.com/img/logo-hi.gif</url>
        </image>
<description><![CDATA[td&#39;s home]]></description>
<link>http://hi.baidu.com/dyerac</link>
<language>zh-cn</language>
<generator>www.baidu.com</generator>
<ttl>5</ttl>


<item>
        <title><![CDATA[在家里DIY了一次咖啡]]></title>
        <link><![CDATA[http://hi.baidu.com/dyerac/blog/item/ff4ccc6d14d6d5f1431694bf.html]]></link>
        <description><![CDATA[
		
		<pre class="note">继冲动的买了虹吸壶、磨豆机和咖啡豆后，昨天又去药店买了酒精，终于今天在家里尝试了一次煮咖啡。<br>味道嘛~~~嘿嘿，考虑的忘记买方糖和牛奶，以及初次不好掌握咖啡豆剂量，其实还算不错的啦:)<br>“唔，至少比速溶的好喝些”~~大家的评语。<br><br>不过过程中咖啡确实蛮香的，看着小火焰闪闪的也蛮有趣滴。很有中学做实验的feel~<br>照片如下... 某人友情提供<br><br>1. 预热<br><span class="cc"><table><tbody><tr><td><img src="http://www.douban.com/view/note/large/59c9b83ca315c32814294a165f066c45/x47971386-1.jpg"></td></tr><tr><td align="center" class="wr pl"> </td></tr></tbody></table></span><br><br>2. 水开始被蒸汽压到上管咯<br><span class="cc"><table><tbody><tr><td><img src="http://www.douban.com/view/note/large/9bbb36feb28515fd8362b2df2d350973/x47971386-2.jpg"></td></tr><tr><td align="center" class="wr pl"> </td></tr></tbody></table></span><br><br><span class="cc"><table><tbody><tr><td><img src="http://www.douban.com/view/note/large/244b798561f105676f1e688a6bfa159e/x47971386-3.jpg"></td></tr><tr><td align="center" class="wr pl"> </td></tr></tbody></table></span><br><br>3. 加磨好的咖啡粉<br><span class="cc"><table><tbody><tr><td><img src="http://www.douban.com/view/note/large/fc92a29f917e1f5574a0cd1e389d1c02/x47971386-4.jpg"></td></tr><tr><td align="center" class="wr pl"> </td></tr></tbody></table></span><br><br>4.搅拌，促进热水萃取咖啡。搅拌几次后就可以移走酒精灯，用冷毛巾冷却下瓶，<br>等萃取后的咖啡流下后即可饮用<br><span class="cc"><table><tbody><tr><td><img src="http://www.douban.com/view/note/large/52665b5c649dc823a15b0f901dd7e43f/x47971386-5.jpg"></td></tr><tr><td align="center" class="wr pl"> </td></tr></tbody></table></span><br><br><span class="cc"><table><tbody><tr><td><img src="http://www.douban.com/view/note/large/2e1fffeede49fc64aa083c7bb3cec868/x47971386-6.jpg"></td></tr><tr><td align="center" class="wr pl"> </td></tr></tbody></table></span></pre> <a href="http://hi.baidu.com/dyerac/blog/item/ff4ccc6d14d6d5f1431694bf.html">阅读全文</a>
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/dyerac/blog/category/%C4%AC%C8%CF%B7%D6%C0%E0">默认分类</a>&nbsp;<a href="http://hi.baidu.com/dyerac/blog/item/ff4ccc6d14d6d5f1431694bf.html#comment">查看评论</a>]]></description>
        <pubDate>2009-10-20  17:36</pubDate>
        <category><![CDATA[默认分类]]></category>
        <author><![CDATA[dyerac]]></author>
		<guid>http://hi.baidu.com/dyerac/blog/item/ff4ccc6d14d6d5f1431694bf.html</guid>
</item>

<item>
        <title><![CDATA[吐槽 - 优乐美的广告]]></title>
        <link><![CDATA[http://hi.baidu.com/dyerac/blog/item/a986b3a7e192ec9fd043582a.html]]></link>
        <description><![CDATA[
		
		其实我想吐槽这个广告很久了......<br>
“你是我的奶茶哦” ，“这样我就可以把你捧着手心” ...... 那确实，而且喝完了就可以扔了，很方便<br>
<br>
<br>
附赠另一则广告的吐槽：<br>
“猜猜我中午吃了什么”<br>
某男吹了一口气，花痴女深情一闻......<br>
“我吃了xx，xx，xx，还有xx哦（唔，总之什么吃了难闻xx就是什么）”<br>
“啊，我怎么什么都没闻到”<br>
......怎么样，大家印象深刻吧？<br>
其实如果旁边围观群臣捂鼻做恶心状递上一盒泰诺，这还确实是一则很好的感冒药广告呢。<br>
<br>
（ps：没病的时候，磕一颗泰诺，确实有点云里雾里小high的感觉......至少我觉得不错） <a href="http://hi.baidu.com/dyerac/blog/item/a986b3a7e192ec9fd043582a.html">阅读全文</a>
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/dyerac/blog/category/%C4%AC%C8%CF%B7%D6%C0%E0">默认分类</a>&nbsp;<a href="http://hi.baidu.com/dyerac/blog/item/a986b3a7e192ec9fd043582a.html#comment">查看评论</a>]]></description>
        <pubDate>2009-09-25  00:32</pubDate>
        <category><![CDATA[默认分类]]></category>
        <author><![CDATA[dyerac]]></author>
		<guid>http://hi.baidu.com/dyerac/blog/item/a986b3a7e192ec9fd043582a.html</guid>
</item>

<item>
        <title><![CDATA[分布式系统开发有感]]></title>
        <link><![CDATA[http://hi.baidu.com/dyerac/blog/item/0dc6f24f434ed93faec3ab0f.html]]></link>
        <description><![CDATA[
		
		转眼在Pyramid组两年了，历经过DFS和DTS两个项目，如今随着DTS的Alpha成功发布，也想试着对旧日知识和经验做一番梳理，写写文章。<br>
<br>
整个系列会分成理论和实战两个方面，前者主要是对开发过程中参考的各篇paper做一番综述，后者则侧重于一些编程心得和设计上的注意点。暂时想到的题目有：<br>
Theory<br>
1. Consensus：讨论各种Consensus算法，以及其在选举、事务方面的应用<br>
2. How to handle CAP：大言不惭的讨论一下分布式系统的CAP solutions，会涵盖How to build a scalable system/GFS/Map Reduce/Bigtable/Chubby等几篇文章<br>
3. something else, 比如压缩算法等等<br>
<br>
Practice<br>
1. TCP/UDP Issues：讲一些在UDP、TCP编程中遇到的问题和解决思路<br>
2. COW &amp; Lock Free<br>
3. Commit Log Mechanism：探讨如何高效的处理commit log，以及如何保证log和memory的一致性<br>
4. 协议设计：总结自己在交互协议、网络协议等方面设计上的问题，包括rpc等等<br>
5. 从GAE设计看Bigtable：尝试从GAE上找到Bigtable改进方法的蛛丝马迹<br>
6. 杂七杂八，比如一些特别需要注重的设计方面，或者一些为付诸实现的想法<br>
<br>
当然，不是所有文章都会公开... <a href="http://hi.baidu.com/dyerac/blog/item/0dc6f24f434ed93faec3ab0f.html">阅读全文</a>
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/dyerac/blog/category/Computer%20Science">Computer Science</a>&nbsp;<a href="http://hi.baidu.com/dyerac/blog/item/0dc6f24f434ed93faec3ab0f.html#comment">查看评论</a>]]></description>
        <pubDate>2009-06-30  16:34</pubDate>
        <category><![CDATA[Computer Science]]></category>
        <author><![CDATA[dyerac]]></author>
		<guid>http://hi.baidu.com/dyerac/blog/item/0dc6f24f434ed93faec3ab0f.html</guid>
</item>

<item>
        <title><![CDATA[用placement new避免强制类型转换时虚函数表指针的破坏]]></title>
        <link><![CDATA[http://hi.baidu.com/dyerac/blog/item/acf7421989ceba4c43a9add3.html]]></link>
        <description><![CDATA[
		
		 
 
 
 
 
 
 
<p class="MsoNormal"><span>有时候我们需要把一段</span><span>char </span><span>的</span><span>buf</span><span>强行转换成某个类或其数组，比如说在使用</span><span>mem_tank</span><span>时，就需要先调用</span><span>write_null_data</span><span>方法获取内存，再转换成需要的类型。</span></p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span>如果要转换的类定义了虚函数，则无论是直接</span><span>memcpy</span><span>还是类型强转后使用</span><span>=</span><span>赋值，都比较危险；对于这种场景，可以使用</span><span>placement new</span><span>来避免，示例代码如下：</span></p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span>#include &lt;stdio.h&gt;</span></p>
<p class="MsoNormal"><span>#include &lt;string.h&gt;</span></p>
<p class="MsoNormal"><span>#include &lt;new&gt;</span></p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span>class A</span></p>
<p class="MsoNormal"><span>{</span></p>
<p class="MsoNormal"><span>public:</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;  A() { a = 1; b = 2; };</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;  int a;</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;  int b;</span></p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  const A &amp; operator=(const A &amp; src)</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  {</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  a = src.a;</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  b = src.b;</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  }</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;  virtual void foo();</span></p>
<p class="MsoNormal"><span>};</span></p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span>class B : public A</span></p>
<p class="MsoNormal"><span>{</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;  int c;</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;  virtual void foo();</span></p>
<p class="MsoNormal"><span>};</span></p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span>void A::foo()</span></p>
<p class="MsoNormal"><span>{</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;  printf(&quot;A Hello!\n&quot;);</span></p>
<p class="MsoNormal"><span>}</span></p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span>void B::foo()</span></p>
<p class="MsoNormal"><span>{</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;  printf(&quot;B Hello!\n&quot;);</span></p>
<p class="MsoNormal"><span>}</span></p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span>int main(int argc, char* argv[])</span></p>
<p class="MsoNormal"><span>{</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;  char szbuf[256];</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  A a;</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;  </span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;  memset(szbuf, 0, sizeof(szbuf));</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;  A* pa = new(szbuf)A();</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;  printf(&quot;A.a=%d, A.b=%d\n&quot;, pa-&gt;a, pa-&gt;b);</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;  pa-&gt;foo();</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;  </span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  a.a = 3;</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  a.b = 4;</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  *pa = a;</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;  printf(&quot;A.a=%d, A.b=%d\n&quot;, pa-&gt;a, pa-&gt;b);</span></p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  pa = new(szbuf)B();</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;  printf(&quot;A.a=%d, A.b=%d\n&quot;, pa-&gt;a, pa-&gt;b);</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;  pa-&gt;foo();</span></p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  fflush(stdout);</span></p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  memset(szbuf, 0 , sizeof(szbuf));</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  A* pa2 = (A*)szbuf;</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  *pa2 = a;</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  //memcpy(pa2, &amp;a, sizeof(pa2));</span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  pa2-&gt;foo();</span></p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span>&nbsp;&nbsp;&nbsp;  return 0;</span></p>
<p class="MsoNormal"><span>}</span></p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span>输出结果如下：</span></p>
<p class="MsoNormal"><span>tandai@tc-dpf-rd /home/tandai&gt;:g++ -o new_t new_t.cpp </span></p>
<p class="MsoNormal"><span>tandai@tc-dpf-rd /home/tandai&gt;:./new_t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  </span></p>
<p class="MsoNormal"><span>A.a=1, A.b=2</span></p>
<p class="MsoNormal"><span>A Hello!</span></p>
<p class="MsoNormal"><span>A.a=3, A.b=4</span></p>
<p class="MsoNormal"><span>A.a=1, A.b=2</span></p>
<p class="MsoNormal"><span>B Hello!</span></p>
<p class="MsoNormal"><span>Segmentation fault (core dumped)</span></p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><strong><span>可以看到，使用</span><span>placement new</span></strong><strong><span>，可以正确的使用虚函数；而强转后</span><span>=</span></strong><strong><span>赋值，由于虚表指针被破坏，程序出</span><span>core</span></strong><strong><span>了</span></strong><span>。不过</span>，使用placement new时要注意，一定得显示的调用类析构函数（防止内存泄漏），而不能调用delete（防止重复释放空间），即new和delete成对，placement new和显示析构成对.</p> <a href="http://hi.baidu.com/dyerac/blog/item/acf7421989ceba4c43a9add3.html">阅读全文</a>
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/dyerac/blog/category/c%2B%2B">c++</a>&nbsp;<a href="http://hi.baidu.com/dyerac/blog/item/acf7421989ceba4c43a9add3.html#comment">查看评论</a>]]></description>
        <pubDate>2009-06-17  22:06</pubDate>
        <category><![CDATA[c++]]></category>
        <author><![CDATA[dyerac]]></author>
		<guid>http://hi.baidu.com/dyerac/blog/item/acf7421989ceba4c43a9add3.html</guid>
</item>

<item>
        <title><![CDATA[GCC的一些扩展]]></title>
        <link><![CDATA[http://hi.baidu.com/dyerac/blog/item/a856ead59166d0cd51da4bd0.html]]></link>
        <description><![CDATA[
		
		<div class="text-article" >
<p><br>
#define min(x, y) ({&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  \<br>
&nbsp;&nbsp;&nbsp;  typeof(x) _min1 = (x);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  \<br>
&nbsp;&nbsp;&nbsp;  typeof(y) _min2 = (y);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  \<br>
&nbsp;&nbsp;&nbsp;  (void) (&amp;_min1 == &amp;_min2);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  \<br>
&nbsp;&nbsp;&nbsp;  _min1 &lt; _min2 ? _min1 : _min2; })</p>
<p><br>
void test_type()<br>
{<br>
&nbsp;&nbsp;&nbsp;  int a = 0;<br>
&nbsp;&nbsp;&nbsp;  typeof(a) b =5;<br>
&nbsp;&nbsp;&nbsp;  printf(&quot;%d\n&quot;, b);<br>
}<br>
<br>
void test_min()<br>
{<br>
&nbsp;&nbsp;&nbsp;  int a = 2;<br>
&nbsp;&nbsp;&nbsp;  int b = 3;<br>
<br>
&nbsp;&nbsp;&nbsp;  printf(&quot;min(a,b) = %d\n&quot;, a &lt;? b);<br>
&nbsp;&nbsp;&nbsp;  printf(&quot;max(a,b) = %d\n&quot;, a &gt;? b);<br>
}<br>
<br>
void test_switch(int a)<br>
{<br>
&nbsp;&nbsp;&nbsp;  switch (a) {<br>
&nbsp;&nbsp;&nbsp;  case 0:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  printf(&quot;%d in 0\n&quot;, a);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  break;<br>
&nbsp;&nbsp;&nbsp;  case 1 ... 7:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  printf(&quot;%d in 1 - 7\n&quot;, a);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  break;<br>
&nbsp;&nbsp;&nbsp;  case 8 ... 15:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  printf(&quot;%d in 8 - 15\n&quot;, a);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  break;<br>
&nbsp;&nbsp;&nbsp;  default:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  printf(&quot;%d in nothing\n&quot;, a);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  break;<br>
&nbsp;&nbsp;&nbsp;  }<br>
}<br>
<br>
typedef struct _sa<br>
{<br>
&nbsp;&nbsp;&nbsp;  int a;<br>
&nbsp;&nbsp;&nbsp;  int b;<br>
<br>
&nbsp;&nbsp;&nbsp;  bool operator &lt;(const _sa &amp; src) const<br>
&nbsp;&nbsp;&nbsp;  {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  bool ret = true;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  if(b &gt; src.b)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  ret = false;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  return ret;<br>
&nbsp;&nbsp;&nbsp;  }<br>
}sa;<br>
<br>
void test_init()<br>
{<br>
&nbsp;&nbsp;&nbsp;  //this extension is not implemented in GNU C++<br>
&nbsp;&nbsp;&nbsp;  //int widths[] = {[0 ... 9] = 1, [10 ... 19] = 2, [20] = 3};<br>
&nbsp;&nbsp;&nbsp;  sa s = {2, 6};<br>
&nbsp;&nbsp;&nbsp;  sa s2 = {6, 2};<br>
&nbsp;&nbsp;&nbsp;  //not supported<br>
&nbsp;&nbsp;&nbsp;  //struct _sa s2 = { .b = 2, .a = 6 };<br>
<br>
&nbsp;&nbsp;&nbsp;  printf(&quot;s.a=%d, s.b=%d, s2.a=%d, s2.b=%d\n&quot;, s.a, s.b, s2.a, s2.b);<br>
}<br>
<br>
//not supported in c++<br>
void test_nested()<br>
{<br>
//&nbsp;&nbsp;&nbsp;  void my_print(int a)<br>
//&nbsp;&nbsp;&nbsp;  {<br>
//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  printf(&quot;my_print: %d; &quot;, a);<br>
//&nbsp;&nbsp;&nbsp;  }<br>
//&nbsp;&nbsp;&nbsp;  printf(&quot;\n&quot;);<br>
//<br>
//&nbsp;&nbsp;&nbsp;  my_print(2);<br>
//&nbsp;&nbsp;&nbsp;  my_print(23);<br>
}<br>
<br>
int test_redirect_call(const char * fmt, ...)<br>
{<br>
&nbsp;&nbsp;&nbsp;  void * param = __builtin_apply_args();<br>
&nbsp;&nbsp;&nbsp;  void * ret = __builtin_apply((void (*)(...))&amp;printf, param, 1024);<br>
&nbsp;&nbsp;&nbsp;  __builtin_return(ret);<br>
}<br>
<br>
void test_typeof_compare()<br>
{<br>
&nbsp;&nbsp;&nbsp;  sa s1 = {2, 8};<br>
&nbsp;&nbsp;&nbsp;  sa s2 = {3, 7};<br>
&nbsp;&nbsp;&nbsp;  sa s3 = {1, 9};<br>
<br>
&nbsp;&nbsp;&nbsp;  sa min = min(s1, s2);<br>
&nbsp;&nbsp;&nbsp;  printf(&quot;min.a=%d, min.b=%d\n&quot;, min.a, min.b);<br>
&nbsp;&nbsp;&nbsp;  min = min(s1, s3);<br>
&nbsp;&nbsp;&nbsp;  printf(&quot;min.a=%d, min.b=%d\n&quot;, min.a, min.b);<br>
&nbsp;&nbsp;&nbsp;  min = min(s3, s2);<br>
&nbsp;&nbsp;&nbsp;  printf(&quot;min.a=%d, min.b=%d\n&quot;, min.a, min.b);<br>
}<br>
<br>
/*<br>
 *<br>
 */<br>
int main(void)<br>
{<br>
&nbsp;&nbsp;&nbsp;  printf(&quot;haha\n&quot;);<br>
&nbsp;&nbsp;&nbsp;  test_type();<br>
&nbsp;&nbsp;&nbsp;  test_min();<br>
&nbsp;&nbsp;&nbsp;  test_switch(0);<br>
&nbsp;&nbsp;&nbsp;  test_switch(9);<br>
&nbsp;&nbsp;&nbsp;  test_init();<br>
&nbsp;&nbsp;&nbsp;  printf(&quot;ret: %d\n&quot;, test_redirect_call(&quot;test_redirect_call: %d\n&quot;, 125));<br>
&nbsp;&nbsp;&nbsp;  test_typeof_compare();<br>
&nbsp;&nbsp;&nbsp;  //test2();<br>
&nbsp;&nbsp;&nbsp;  //test_sem();<br>
&nbsp;&nbsp;&nbsp;  //test_timeused();<br>
&nbsp;&nbsp;&nbsp;  //test_str_cmp();<br>
&nbsp;&nbsp;&nbsp;  //&nbsp;&nbsp;&nbsp;  for(int i=0; i&lt;20; i++)<br>
&nbsp;&nbsp;&nbsp;  //&nbsp;&nbsp;&nbsp;  {<br>
&nbsp;&nbsp;&nbsp;  //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  test_binary_search(i);<br>
&nbsp;&nbsp;&nbsp;  //&nbsp;&nbsp;&nbsp;  }<br>
&nbsp;&nbsp;&nbsp;  return 0;<br>
}</p>
<p> </p>
<p>//--result--------------------------</p>
<p>haha<br>
5<br>
min(a,b) = 2<br>
max(a,b) = 3<br>
0 in 0<br>
9 in 8 - 15<br>
s.a=2, s.b=6, s2.a=6, s2.b=2<br>
test_redirect_call: 125<br>
ret: 24<br>
min.a=3, min.b=7<br>
min.a=2, min.b=8<br>
min.a=3, min.b=7<br>
dt_threadpool.cpp:396 un-init</p>
<p> </p>
<p>//comments</p>
<p>感觉typeof和__builtin_apply_args系列比较有用，__inline__ 或 __attribute__((deprecated)) 也比较有用。详细可以参见下面文章：</p>
<p>http://www.ibm.com/developerworks/cn/linux/l-gcc-hacks/</p>
<p>http://gcc.gnu.org/onlinedocs/gcc-3.0.1/gcc.html#SEC_Top （extensions章节）</p>
<p>----------------------------------------------------------------------------------</p>
<h3 class="title-article margin-top"><strong><strong>GCC下成员函数指针是16bytes</strong></strong></h3>
<p>很变态的问题。。。</p>
<p>其实是32位机器上是8bytes，64位机器上是16bytes；因为成员函数的指针不是一个指针而是一个结构。测试如下：</p>
<p><br>
  1 #include &lt;stdio.h&gt;<br>
  2 <br>
  3 class Test<br>
  4 {<br>
  5 public:<br>
  6&nbsp;&nbsp;&nbsp;&nbsp;  void print() {<br>
  7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  }<br>
  8 };<br>
  9 <br>
 10 void print2(){<br>
 11&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <br>
 12 }<br>
 13 <br>
 14 int main()<br>
 15 {&nbsp;&nbsp;  <br>
 16&nbsp;&nbsp;&nbsp;&nbsp;  printf( &quot;%d\n&quot;, sizeof( &amp;Test::print ) );<br>
 17&nbsp;&nbsp;&nbsp;&nbsp;  printf( &quot;%d\n&quot;, sizeof( &amp;print2 ) );&nbsp;&nbsp;&nbsp;&nbsp;  <br>
 18 }<br>
 19&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p> </p>
<p>输出如下：</p>
<p>tandai@tc-dpf-rd /home/tandai&gt;:./test<br>
16<br>
8</p>
<p>-------------------------------------------------------------</p>
<p>GCC的warn_unused_result扩展:</p>
<p> </p>
<p>
 
 
 
 
 
 
 </p>
<p class="MsoNormal"><span>这个扩展可以在编译期用来<span style="color: red;">检查调用者是否判断了函数的返回值</span>，对于一些关键的基础函数申明该属性，可以减少人为错误，与大家分享之。</span></p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span>使用示例如下：</span></p>
<p align="left" style="text-align: left;" class="MsoNormal"><strong><span style="font-size: 10pt; Courier New&quot;; color: rgb(127, 0, 85);">int</span></strong><span style="font-size: 10pt; Courier New&quot;; color: black;"> </span><strong><span style="font-size: 10pt; Courier New&quot;; color: rgb(127, 0, 85);">__attribute__</span></strong><span style="font-size: 10pt; Courier New&quot;; color: black;">((warn_unused_result)) <strong>check</strong>()</span><span style="font-size: 10pt; Courier New&quot;;"></span></p>
<p align="left" style="text-align: left;" class="MsoNormal"><span style="font-size: 10pt; Courier New&quot;; color: black;">{</span><span style="font-size: 10pt; Courier New&quot;;"></span></p>
<p align="left" style="text-align: left;" class="MsoNormal"><span style="font-size: 10pt; Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;  </span><strong><span style="font-size: 10pt; Courier New&quot;; color: rgb(127, 0, 85);">return</span></strong><span style="font-size: 10pt; Courier New&quot;; color: black;"> 1;</span><span style="font-size: 10pt; Courier New&quot;;"></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; Courier New&quot;; color: black;">}</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; Courier New&quot;; color: black;"> </span></p>
<p align="left" style="text-align: left;" class="MsoNormal"><strong><span style="font-size: 10pt; Courier New&quot;; color: rgb(127, 0, 85);">int</span></strong><span style="font-size: 10pt; Courier New&quot;; color: black;"> <strong>main</strong>(</span><strong><span style="font-size: 10pt; Courier New&quot;; color: rgb(127, 0, 85);">void</span></strong><span style="font-size: 10pt; Courier New&quot;; color: black;">)</span><span style="font-size: 10pt; Courier New&quot;;"></span></p>
<p align="left" style="text-align: left;" class="MsoNormal"><span style="font-size: 10pt; Courier New&quot;; color: black;">{</span><span style="font-size: 10pt; Courier New&quot;;"></span></p>
<p align="left" style="text-align: left;" class="MsoNormal"><span style="font-size: 10pt; Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;  </span><strong><span style="font-size: 10pt; Courier New&quot;; color: rgb(127, 0, 85);">int</span></strong><span style="font-size: 10pt; Courier New&quot;; color: black;"> ret = 0;</span><span style="font-size: 10pt; Courier New&quot;;"></span></p>
<p align="left" style="text-align: left;" class="MsoNormal"><span style="font-size: 10pt; Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;  <u>check();</u></span><span style="font-size: 10pt; Courier New&quot;;"></span></p>
<p align="left" style="text-align: left;" class="MsoNormal"><span style="font-size: 10pt; Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;  ret = check();</span><span style="font-size: 10pt; Courier New&quot;;"></span></p>
<p align="left" style="text-align: left;" class="MsoNormal"><span style="font-size: 10pt; Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;  </span><strong><span style="font-size: 10pt; Courier New&quot;; color: rgb(127, 0, 85);">if</span></strong><span style="font-size: 10pt; Courier New&quot;; color: black;">(0 != (ret = check()))</span><span style="font-size: 10pt; Courier New&quot;;"></span></p>
<p align="left" style="text-align: left;" class="MsoNormal"><span style="font-size: 10pt; Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;  {</span><span style="font-size: 10pt; Courier New&quot;;"></span></p>
<p align="left" style="text-align: left;" class="MsoNormal"><span style="font-size: 10pt; Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  </span><span style="font-size: 10pt; Courier New&quot;; color: rgb(63, 127, 95);">//<u>bla</u> <u>bla</u>...</span><span style="font-size: 10pt; Courier New&quot;;"></span></p>
<p align="left" style="text-align: left;" class="MsoNormal"><span style="font-size: 10pt; Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;  }</span><span style="font-size: 10pt; Courier New&quot;;"></span></p>
<p style="text-indent: 18pt;" class="MsoNormal"><span style="font-size: 10pt; Courier New&quot;; color: black;">ret = check();</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; Courier New&quot;; color: black;">}</span></p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span>编译结果如下：</span></p>
<p align="left" style="text-align: left;" class="MsoNormal"><span style="font-size: 10pt; Courier New&quot;; color: black;">tm_td_tester.cpp: In function `int main()':</span><span style="font-size: 10pt; Courier New&quot;;"></span></p>
<p align="left" style="text-align: left;" class="MsoNormal"><span style="font-size: 10pt; Courier New&quot;; color: black;">tm_td_tester.cpp:365:</span><span style="font-size: 10pt; Courier New&quot;; color: red;"> <strong>warning</strong></span><span style="font-size: 10pt; Courier New&quot;; color: black;">: ignoring return value of `int check()', declared with attribute warn_unused_result</span><span style="font-size: 10pt; Courier New&quot;;"></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; Courier New&quot;; color: black;">make: *** [tm_td_tester.o] Error 1</span></p>
<p class="MsoNormal"><span style="color: rgb(98, 34, 93);"> </span></p>
<span style="font-size: 10.5pt;  color: rgb(98, 34, 93);">可以看到，申明了该属性的函数，调用者必须使用其返回值（或者检查，或者将返回值赋予某个变量），不然则会有编译错误。</span>
<p> </p>
</div> <a href="http://hi.baidu.com/dyerac/blog/item/a856ead59166d0cd51da4bd0.html">阅读全文</a>
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/dyerac/blog/category/Unix%20Tool">Unix Tool</a>&nbsp;<a href="http://hi.baidu.com/dyerac/blog/item/a856ead59166d0cd51da4bd0.html#comment">查看评论</a>]]></description>
        <pubDate>2009-06-17  22:02</pubDate>
        <category><![CDATA[Unix Tool]]></category>
        <author><![CDATA[dyerac]]></author>
		<guid>http://hi.baidu.com/dyerac/blog/item/a856ead59166d0cd51da4bd0.html</guid>
</item>

<item>
        <title><![CDATA[慕容复是我所知最坚韧不拔的复国王子]]></title>
        <link><![CDATA[http://hi.baidu.com/dyerac/blog/item/d0abba3671d122d4a2cc2b4f.html]]></link>
        <description><![CDATA[
		
		<div class="text-article">
<p>慕容复是我所知最坚韧不拔的复国王子！！</p>
<p> </p>
<p>据天龙八部记载，慕容复是大燕国的王室后代。大燕国还是东晋时候的北方政权，最后一个慕容氏的政权后燕于407年被北燕攻灭（北燕已是鲜卑冯氏政权）。</p>
<p>那么天龙八部是什么时候的事呢？由于天龙八部里面出现过青年时期的完颜阿骨打，而阿骨打生于1068年......也就是说，即使天龙八部里阿骨打只有1岁，1068+1-407 = 660 ！！！</p>
<p> </p>
<p>天啊，可怜的慕容家族，原来你们历经北魏、西魏、北周（假设他们一直在北方）、隋、大唐、后梁、后唐、后晋、后汉、后周一直到北宋这600多年，不抛弃、不放弃，一直在卧薪尝胆、处心积虑......</p>
<p> </p>
<p>ps：其实北宋也就那么屁大点地</p>
<p><img src="http://imgsrc.baidu.com/baike/pic/item/d041a4a14c965d98471064bf.jpg"></p>
</div> <a href="http://hi.baidu.com/dyerac/blog/item/d0abba3671d122d4a2cc2b4f.html">阅读全文</a>
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/dyerac/blog/category/For%20Fun">For Fun</a>&nbsp;<a href="http://hi.baidu.com/dyerac/blog/item/d0abba3671d122d4a2cc2b4f.html#comment">查看评论</a>]]></description>
        <pubDate>2009-06-17  18:35</pubDate>
        <category><![CDATA[For Fun]]></category>
        <author><![CDATA[dyerac]]></author>
		<guid>http://hi.baidu.com/dyerac/blog/item/d0abba3671d122d4a2cc2b4f.html</guid>
</item>

<item>
        <title><![CDATA[绿坝-花季护航软件技术分析（转）]]></title>
        <link><![CDATA[http://hi.baidu.com/dyerac/blog/item/76b4f824fd066b23d40742ae.html]]></link>
        <description><![CDATA[
		
		<p><a target="_blank" href="https://docs.google.com/View?id=afk7vnz54wt_12f8jzj9gw"><span style="color: rgb(153, 153, 153);">原文地址：<br>
</span></a></p>
<p><a target="_blank" href="https://docs.google.com/View?id=afk7vnz54wt_12f8jzj9gw"><span style="color: rgb(153, 153, 153);">https://docs.google.com/View?id=afk7vnz54wt_12f8jzj9gw</span></a></p>
<p> </p>
<p>自己看吧，同学们不要怪我懒，我花了半个小时去关键字，甚至删光了中文只剩下英文，校内还说文章有不适内容...</p>
<p> </p>
<p>本来我只对绿坝的图像识别感兴趣，按照这篇文章说的...靠，算法都跟我以前自己随便写的demo一样....鄙视之！我以前还会边旋转图片边识别人脸，不晓得这个绿坝会不会。算了，大家都知道怎么回事~</p>
<p> </p>
我决定用绿坝作为我学习逆向工程的素材了，恩！ <a href="http://hi.baidu.com/dyerac/blog/item/76b4f824fd066b23d40742ae.html">阅读全文</a>
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/dyerac/blog/category/Computer%20Science">Computer Science</a>&nbsp;<a href="http://hi.baidu.com/dyerac/blog/item/76b4f824fd066b23d40742ae.html#comment">查看评论</a>]]></description>
        <pubDate>2009-06-11  14:37</pubDate>
        <category><![CDATA[Computer Science]]></category>
        <author><![CDATA[dyerac]]></author>
		<guid>http://hi.baidu.com/dyerac/blog/item/76b4f824fd066b23d40742ae.html</guid>
</item>

<item>
        <title><![CDATA[A brief history of Consensus, 2PC and Transaction Commit]]></title>
        <link><![CDATA[http://hi.baidu.com/dyerac/blog/item/2174d67f07a1f60029388a5f.html]]></link>
        <description><![CDATA[
		
		<h3 class="post-title">A brief history of Consensus, 2PC and Transaction Commit.</h3>
<p>by Mark Mc Keown</p>
<p>http://betathoughts.blogspot.com/2007/06/brief-history-of-consensus-2pc-and.html</p>
<p>This is a potted history of consensus, transactions and 2PC. Reading the literature on consensus is difficult because the language changes (consensus was originally called agreement), the results come in an order that isn&rsquo;t logical, and the whole framework for describing distributed algorithms evolved in parallel with the work. Also, there are few books other than Lynch&rsquo;s Distributed Algorithms that cover the subject.</p>
<p>Papers are discussed in the order that makes most sense, not in the order they were published.</p>
<p>The first instance of the consensus problem that I am aware of is in Lamport&rsquo;s <a href="http://research.microsoft.com/users/lamport/pubs/time-clocks.pdf">&ldquo;Time, Clocks and the Ordering of Events in a Distributed System&rdquo; (1978)</a>, though it is not explicitly declared as a consensus or agreement problem. In this paper Lamport discusses how messages take a finite time to travel between processors and draws an analogy with Einstein&rsquo;s special relativity. Discussing Einstein&rsquo;s theory with respect to distributed systems is popular recently in the blogsphere, but in 1978 Lamport give a complete analysis with space-time diagrams and all. The issue is that in a distributed system you cannot tell if event A happened before event B, unless A caused B in some way. Each observer can see events happen in a different order, except for events that cause each other, ie there is only a partial ordering of events in a distributed system. Lamport defines the &ldquo;happens before&rdquo; relationship and operator, and goes on to give an algorithm that provides a total ordering of events in a distributed system, so that each process sees events in the same order as every other process.</p>
<p>Lamport also introduces the concept of a distributed state machine: start a set of deterministic state machines in the same state and then make sure they process the same messages in the same order. Each machine is now a replica of the others. The key problem is making each replica agree what is the next message to process: a consensus problem. This is what the algorithm for creating a total ordering of events does, it provides an agreed ordering for the delivery of messages. However, the system is not fault tolerant; if one process fails that others have to wait for it to recover.</p>
<p>Around the same time as this paper, Gray described 2PC in <a href="http://research.microsoft.com/%7EGray/papers/DBOS.pdf">&ldquo;Notes on Database Operating Systems&rdquo; (1979)</a>. Unfortunately 2PC would block if the TM (Transaction Manager) fails at the wrong time. Skeen showed in <a href="http://www.cs.cornell.edu/courses/cs614/2004sp/papers/Ske81.pdf">&ldquo;NonBlocking Commit Protocols&rdquo; (1981)</a>that for a distributed transactions you needed a 3 phrase commit algorithm to avoid the blocking problems associated with 2PC. The problem was coming up with a nice 3PC algorithm, this would only take nearly 25 years!</p>
<p>Fischer, Lynch and Paterson showed that distributed consensus was impossible in an asynchronous system with just one faulty process in <a href="http://theory.lcs.mit.edu/tds/papers/Lynch/jacm85.pdf">&ldquo;Impossibility of distributed consensus with one faulty process&rdquo; (1985)</a>, this famous result is known as the &ldquo;FLP&rdquo; result. By this time &ldquo;consensus&rdquo; was the name given to the problem of getting a bunch of processors to agree a value. In an asynchronous system (where processors run at arbitrary speeds and messages can take an arbitrarily long time to travel between processors) with a perfect network (all messages are delivered, messages arrive in order and can not be duplicated) distributed consensus is impossible with just one faulty process (even just a fail-stop). The kernel of the problem is that you cannot tell the difference between a process that has stopped and one that is running very slowly, making dealing with faults in an asynchronous system almost impossible. The paper was also important because it demonstrated how to show something was impossible: show that all algorithms that solve the problem must have some property, then show that this property is impossible, ie proof by contradiction. (This approach was only re-learned as Turing used it in the halting problem)</p>
<p>By this stage people realized that a distributed algorithm has two properties: safety and liveness. Safety means nothing bad happens, while liveness means that something good eventually happens. 2PC is an asynchronous consensus algorithm, all processes must agree on either commit or abort for a transaction. 2PC is safe: no bad data is ever written to the databases, but its liveness properties aren&rsquo;t great: if the TM fails at the wrong point the system will block.</p>
<p>Also by this stage people thought of distributed systems as being synchronous (processes run at known rates, and messages are delivered in known bounds of time) or asynchronous (processes run at unknown and arbitrary rates, and messages can take unbounded time to be delivered). The asynchronous case is more general than the synchronous case: an algorithm that works for an asynchronous system will also work for a synchronous system, but not vice versa. You can treat a synchronous system as a special case of an asynchronous system that just happens to have bounds on the time it takes to deliver a message.</p>
<p>Before FLP, there was the <a href="http://research.microsoft.com/users/lamport/pubs/byz.pdf">&ldquo;The Byzantine Generals Problem&rdquo; (1982)</a> paper. In this form of the consensus problem the processes can lie, and they can actively try to deceive other processes. This problem looks harder than the FLP result, but it does have a solution for the synchronous case (though when the Byzantine Generals paper was written the distinction between asynchronous and synchronous systems was not explicit). The solution is expensive in the number of messages exchanged, and the number of rounds of messages required. The problem originally came from the aerospace industry: what would happen if sensors gave false information on an plane (clearly the system could be treated as synchronous).</p>
<p>In 1986 there was a get together of the distributed systems people who were interested in consensus and the transaction people. At the time the best consensus algorithm was the Byzantine Generals, but this was too expensive to use for transactions. Jim Gray wrote up a note on the meeting: <a href="http://research.microsoft.com/%7EGray/papers/TandemTR88.6_ComparisonOfByzantineAgreementAndTwoPhaseCommit.pdf">&ldquo;A Comparison of the Byzantine Agreement Problem and the Transaction Commit Problem.&rdquo; (1987) </a>.</p>
<p>The paper contains this in the introduction <img class="wp-smiley" alt=":-)" src="http://www.w4t.net.cn/blog/wp-includes/images/smilies/icon_smile.gif"></p>
<p><span style="font-style: italic;">&ldquo;Prior to the conference, it was widely believed that the transaction commit problem faced by distributed systems is a degenerate form of the Byzantine Generals Problem studied by academe. Perhaps the most useful consequence of the conference was to show that these two problems have little in common.&rdquo;</span></p>
<p>Eventually distributed transactions would be seen as a version of consensus, called uniform consensus (see <a href="http://infoscience.epfl.ch/getfile.py?recid=88273&amp;mode=best">&ldquo;Uniform consensus is harder than consensus&rdquo; (2000)</a>). With uniform consensus all processes must agree on a value, even the faulty ones - a transaction should only commit if all RMs are prepared to commit. Most forms of consensus are only concerned with having the non-faulty processes agree. Uniform consensus is more difficult than general consensus.</p>
<p>Eventually Lamport came up with the Paxos consensus algorithm, described in <a href="http://research.microsoft.com/users/lamport/pubs/lamport-paxos.pdf">&ldquo;The Part-Time Parliament&rdquo; (submitted in 1990, published 1998)</a>. Unfortunately the analogy with Greek democracy failed badly with people finding the paper very difficult to understand, and the paper was ignored until its case was taken up by Butler Lampson in <a href="http://research.microsoft.com/lampson/58-Consensus/Acrobat.pdf">&ldquo;How to Build a Highly Availability System using Consensus&rdquo; (1996)</a>. This paper provides a good introduction to building fault tolerant systems and Paxos. Later Lamport would publish <a href="http://research.microsoft.com/users/lamport/pubs/paxos-simple.pdf">&ldquo;Paxos Made Simple (2001)</a>.</p>
<p>The kernel of Paxos is that given a fixed number of processes, any majority of them must have at least one process in common. For example given three processes A, B and C the possible majorities are: AB, AC, or BC. If a decision is made when one majority is present eg AB, then at any time in the future when another majority is available at least one of the processes can remember what the previous majority decided. If the majority is AB then both processes will remember, if AC is present then A will remember and if BC is present then B will remember.</p>
<p>Paxos can tolerate lost messages, delayed messages, repeated messages, and messages delivered out of order. It will reach consensus if there is a single leader for long enough that the leader can talk to a majority of processes twice. Any process, including leaders, can fail and restart; in fact all processes can fail at the same time, the algorithm is still safe. There can be more than one leader at a time.</p>
<p>Paxos is an asynchronous algorithm; there are no explicit timeouts. However, it only reaches consensus when the system is behaving in a synchronous way, ie messages are delivered in a bounded period of time; otherwise it is safe. There is a pathological case where Paxos will not reach consensus, in accordance to FLP, but this scenario is relatively easy to avoid in practice.</p>
<p>Clearly dividing systems into synchronous and asynchronous is too broad a distinction, and Dwork, Lynch and Stockmeyer defined partially synchronous systems in <a href="http://theory.lcs.mit.edu/tds/papers/Lynch/jacm88.pdf">&ldquo;Consensus in the presence of partial synchrony&rdquo; (1988) </a>. There are two versions of partial synchronous system: in one processes run at speeds within a known range and messages are delivered in bounded time but the actual values are not known a priori; in the other version the range of speeds of the processes and the upper bound for message deliver are known a priori, but they will only start holding at some unknown time in the future. The partial synchronous model is a better model for the real world than either the synchronous or asynchronous model; networks function in a predicatable way most of the time, but occasionally go crazy.</p>
<p>Lamport and Gray went on to apply Paxos to the distributed transaction commit problem in <a href="http://research.microsoft.com/research/pubs/view.aspx?tr_id=701">&ldquo;Consensus on Transaction Commit&rdquo; (2005)</a>. They used Paxos to effectively replicate the TM of 2PC, and used an instance of Paxos for each RM involved in the transaction to agree whether that RM could commit the transaction. On the face of it, using an instance of Paxos per RM looks expensive, but it turns out that it is not. Paxos Commit will complete in two phases for the fault free case, ie it has the same message delay as 2PC, though more messages are exchanged. A third phase is only required if there is a fault, in accordance to the Skeen result. Given 2n+1 TM replicas Paxos Commit will complete with up to n faulty replicas. Paxos Commit does not use Paxos to solve the transaction commit problem directly, ie it is not used to solve uniform consensus, rather it is used to make the system fault tolerant.</p>
<p>Any argument that distributed transactions should not be used because 2PC is blocking is a void, because Paxos Commit addresses the blocking issue.</p>
<p>Recently there has been some discussion of the CAP conjecture: Consistency, Availability and Partition. The conjecture asserts that you cannot have all three in a distributed system: a system that is consistent, that can have faulty processes and that can handle a network partition.</p>
<p>We can examine CAP by equating consistency with consensus. For an asynchronous system we cannot reach consensus with one faulty process, FLP, so we cannot have consistency and availability for an asynchronous system!</p>
<p>Now take a Paxos system with three nodes: A, B and C. We can reach consensus if two nodes are working, ie we can have consistency and availability. Now if C becomes partitioned and C is queried, it cannot respond because it cannot communicate with the other nodes; it doesn&rsquo;t know whether it has been partitioned, or if the other two nodes are down, or if the network is being very slow. The other two nodes can carry on, because they can talk to each other and they form a majority. So for the CAP conjecture, Paxos does not handle a partition because C cannot respond to queries. However, we could engineer our way around this. If we are inside a data center we can use two independent networks (Paxos doesn&rsquo;t mind if messages are repeated). If we are on the internet, then we could have our client query all nodes A, B and C, and if C is partitioned the client can query A or B unless it is partitioned in a similar way to C.</p>
<p>For a synchronous network, if C is partitioned it can learn that it is partitioned if it does not receive messages in a fixed period of time, and thus can declare itself down to the client.</p>
<p>Paxos, Paxos Commit and HTTP/REST have been combined to build a highly available co-allocation system for Grid computing, details of which can be found here <a href="http://www.cct.lsu.edu/%7Emaclaren/HARC/">HARC</a>, there are also more references in this paper: <a href="http://www.allhands.org.uk/2006/proceedings/papers/624.pdf">&ldquo;Co-Allocation, Fault Tolerance and Grid Computing&rdquo; (2006)</a>.</p> <a href="http://hi.baidu.com/dyerac/blog/item/2174d67f07a1f60029388a5f.html">阅读全文</a>
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/dyerac/blog/category/Computer%20Science">Computer Science</a>&nbsp;<a href="http://hi.baidu.com/dyerac/blog/item/2174d67f07a1f60029388a5f.html#comment">查看评论</a>]]></description>
        <pubDate>2009-06-07  15:44</pubDate>
        <category><![CDATA[Computer Science]]></category>
        <author><![CDATA[dyerac]]></author>
		<guid>http://hi.baidu.com/dyerac/blog/item/2174d67f07a1f60029388a5f.html</guid>
</item>

<item>
        <title><![CDATA[都屏蔽，我也来屏蔽校内广告]]></title>
        <link><![CDATA[http://hi.baidu.com/dyerac/blog/item/f79fd797e683da6554fb967e.html]]></link>
        <description><![CDATA[
		
		<div class="text-article">
<p>校内首页那个啥啥天使魔鬼的内衣广告太龌龊了，我说你好歹搞给分辨率清晰一点的图片呀，现在这个模模糊糊恶心死了的。在firefox的adblock plus插件中加入如下规则即可屏蔽：</p>
<p> </p>
<p>http://jebe.xnimg.cn/*</p>
<p> </p>
<p>恩，现在首页的header和footer都清凉了...</p>
</div> 
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/dyerac/blog/category/Computer%20Application">Computer Application</a>&nbsp;<a href="http://hi.baidu.com/dyerac/blog/item/f79fd797e683da6554fb967e.html#comment">查看评论</a>]]></description>
        <pubDate>2009-06-03  19:05</pubDate>
        <category><![CDATA[Computer Application]]></category>
        <author><![CDATA[dyerac]]></author>
		<guid>http://hi.baidu.com/dyerac/blog/item/f79fd797e683da6554fb967e.html</guid>
</item>

<item>
        <title><![CDATA[适用于hoopchina（虎扑）和popgo（漫游）的AutoPager自动翻页设置]]></title>
        <link><![CDATA[http://hi.baidu.com/dyerac/blog/item/da7b7c100be0dd09213f2ed1.html]]></link>
        <description><![CDATA[
		
		<a href="http://www.w4t.net.cn/blog/?p=35">适用于hoopchina（虎扑）和popgo（漫游）的自动翻页设置，当然，前提是你用firefox并安装了autopager插件</a>
<p>for hoopchina.com:</p>
<p>&lt;autopager&gt;<br>
&lt;site&gt;&lt;urlPattern&gt;http://bbs.hoopchina.com/*&lt;/urlPattern&gt;<br>
&lt;guid&gt;D661475F-94D9-7FE3-417A-D884-BFBD-5D3D&lt;/guid&gt;<br>
&lt;margin&gt;1&lt;/margin&gt;<br>
&lt;owner&gt;dyerac&lt;/owner&gt;<br>
&lt;urlIsRegex&gt;true&lt;/urlIsRegex&gt;<br>
&lt;quickLoad&gt;true&lt;/quickLoad&gt;<br>
&lt;contentXPath&gt;//div[@class='page_box']&lt;/contentXPath&gt;<br>
&lt;contentXPath&gt;//table[@id='pl']&lt;/contentXPath&gt;<br>
&lt;contentXPath&gt;//body&lt;/contentXPath&gt;<br>
&lt;testLink&gt;http://bbs.hoopchina.com/670864.html?vthread&lt;/testLink&gt;<br>
&lt;linkXPath&gt;//a[@class='next' and @title='下一页'] | //table[3]/tbody/tr/td[@align='left']/span[1]/following-sibling::a[1]&lt;/linkXPath&gt;<br>
&lt;desc&gt;http://bbs.hoopchina.com/670864.html?vthread&lt;/desc&gt;<br>
&lt;/site&gt;<br>
&lt;/autopager&gt;</p>
<p>for popgo.net:</p>
<p>&lt;autopager&gt;<br>
&lt;site&gt;&lt;urlPattern&gt;popgo.net/*&lt;/urlPattern&gt;<br>
&lt;guid&gt;EEC01EEE-5707-D109-F0A8-17EE-AC12-4D23&lt;/guid&gt;<br>
&lt;margin&gt;1&lt;/margin&gt;<br>
&lt;owner&gt;dyerac&lt;/owner&gt;<br>
&lt;urlIsRegex&gt;true&lt;/urlIsRegex&gt;<br>
&lt;quickLoad&gt;true&lt;/quickLoad&gt;<br>
&lt;contentXPath&gt;//center&lt;/contentXPath&gt;<br>
&lt;testLink&gt;http://popgo.net/bbs/forumdisplay.php?s=&amp;amp;forumid=11&amp;amp;daysprune=30&amp;amp;sortorder=&amp;amp;sortfield=lastpost&amp;amp;perpage=40&amp;amp;pagenumber=3&lt;/testLink&gt;<br>
&lt;linkXPath&gt;//a[@title='下一页']&lt;/linkXPath&gt;<br>
&lt;desc&gt;http://popgo.net/bbs/forumdisplay.php?s=&amp;amp;forumid=11&amp;amp;daysprune=30&amp;amp;sortorder=&amp;amp;sortfield=lastpost&amp;amp;perpage=40&amp;amp;pagenumber=3&lt;/desc&gt;<br>
&lt;/site&gt;<br>
&lt;/autopager&gt;</p>
<p>&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&ndash;</p>
<p>PHPWind 老版本的html代码真可怕…都不用div的….</p>
<p>useful links:</p>
<p>http://www.teesoft.info/component/option,com_wrapper/Itemid,86/</p> <a href="http://hi.baidu.com/dyerac/blog/item/da7b7c100be0dd09213f2ed1.html">阅读全文</a>
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/dyerac/blog/category/Computer%20Application">Computer Application</a>&nbsp;<a href="http://hi.baidu.com/dyerac/blog/item/da7b7c100be0dd09213f2ed1.html#comment">查看评论</a>]]></description>
        <pubDate>2009-06-02  12:20</pubDate>
        <category><![CDATA[Computer Application]]></category>
        <author><![CDATA[dyerac]]></author>
		<guid>http://hi.baidu.com/dyerac/blog/item/da7b7c100be0dd09213f2ed1.html</guid>
</item>


</channel>
</rss>