2013-08-20

Busy wait, Sleep(0), Sleep(1), Sleep(1000)

* Busy wait, or spin wait: not required for most of the cases
* Sleep(0): fairly good choice
  * if you don't know how long to "sleep", or need to "sleep" less than 1ms
  * if it's not constraint to a single CPU/core
  * if you don't care about the "high" CPU usage
  * if you need an immediate response
* Sleep(1): "sleep" a little bit, but normally more than 1ms
  * if you don't need immediate response
  * if you'd like give out the time slice anyway
  * if you want a "lower" CPU usage than Sleep(1)
* Sleep(1000): just an arbitrary selected number
  * if it's not likely to happen
  * if you are waiting for another time consuming counter part

"Sleep()" is not sleep, but tells the scheduler "Don't bother me for at least some time".

Sleep(0) has a special meaning and handled differently than other values.

WaitOnAddress() seems promising, but:
* seems cause more CPU usage
* with more wall time
Compared to my Sleep(0) version.

Will check the testing/benchmark code later. But, it seems so now.
And the document on MSDN seems at least not reflecting the implementation.

I already sent comments with questions on the documentation and the underlying tech, via email by clicking the bottom link.
I don't expect any (immediate) response. But, before I get any response, I will stop there, no using/testing WaitOnAddress anymore.

Some obvious questions:
* Parameter dwMilliseconds
  * What does "indefinite" mean? If given 0.
  * An optional parameter?
* The example code
  * Why not check the return value?
  * Have you noticed a race condition of using CapturedValue?

Sleep(0) might be further improved, both the performance/speed and power consumption. I'm not sure about the first claim, neither have any knowledge on power consumption.
I'm sure of the implementation of ReaderWriterLockSlim (C#):
* Why not use existing WIN API, like AcquireSRWLockExclusive?
* Why busy wait, then Sleep(0), then Sleep(1)?
* And how to choose the arbitrary numbers for busy wait and Sleep(0)?
* It is with the best performance, or has some compromises?

Anyway, it seems the same approach as the guys from Intel did.
I will give it a try, when I have time.
But, actually, I don't care about performance too much. So, if there is no big improvement (like 10x), I will still use the simple Sleep(0).

Just now, it is only tested against wall time (CPU instruction).
Maybe I'll test it against wall time (performance counter), and analysis the stdev besides just avg.

2013-01-24

利用政策漏洞,套钱买房

利用政策漏洞,套钱买房

http://www.newsmth.net/bbstcon.php?board=SchoolEstate&gid=45221

发信人: evangy (望月寻音), 信区: SchoolEstate
标  题: 超级攻略:你没钱,还想再买个学区房,我来告诉你办法.
发信站: 水木社区 (Tue Jan 22 21:36:57 2013), 站内

竟然到十大了.本文纯属茶余饭后的讨论贴.

一个外地人,在北京需要多少套房子?
答案是4套起,自己住一套,父母住一套,岳父母一套,再给孩子准备一套,当然,再有一套郊区度假的最好.
但太多的人只有一套房,父母接来北京后,明显不够住.
可以参考以下的方法.

条件
1.夫妻名下有房屋(最好全款,能估高一点)
2.夫妻至少一方有公积金或商贷资格,都要有购房资格.
3.房屋最好满5年,唯一(非必要)

流程如下:
一,假离婚,将已有房屋过到一方名下(如只有一方可用公积金,需过户到无公积金的一方身上)

二,假离婚后,假设LP为无房户,LG为有房户,无房户LP"购买"有房户LG的房屋,如满5且唯一,税非常低,按照指导价过户即可.无房户LP交易中要申请公积金或商业贷款.这里假设申请80w公积金.

三,现在,仍然一房为无房户,一方为有房户(注意,换过来拉,LG无房,LP有房),此时,无房LG手中神奇的多出了80w,80w耶,来自步骤二!无房LG再去购买住房(注意:这个是学区房,不是刚才自己买卖的那套,那套房本已经盖银行抵押章了.),此时我们假设买新房,算首套,再申请80w的公积金!(商贷可申请更多)

四,现在LG买到了80w+80w的新房,当然要复婚了,现在二套房入手,贷款只要8K多,房租4K+,毫无压力的日子啊~~

五,如愿意,可重复以上步骤(成本会增加)

课后作业:
160万不够买学区房怎么办??
提供的思路是:丈夫娶丈母娘,老婆嫁公公。。。。。。。

--
※ 修改:·evangy 于 Jan 23 19:25:01 2013 修改本文·[FROM: 123.112.166.*]
※ 来源:·水木社区 http://www.newsmth.net·[FROM: 123.112.152.*]