2007年4月11日星期三

Some Experiences on Big Project

Principle1: do NOT give more than necessary access permissions, for example:
1. define variables used exclusively in only one function as local;
2. define variables used exclusively in only one file as static;
3. declare read only argument as const *;

Principle2: tag code snippet according to its semantics;
1. declare all global variables with a tag like GLOBAL, so that you can list them;
2. use static_cast instead of forced type conversion;

Principle3: locality in SE:
1. gather all operations on some type of object in one or two files;

2007年3月31日星期六

Time to Wakeup a Thread in Linux

Abstract:
In multithreaded programming, it is sometimes desirable to have some process blocked for a specific event to happen. For better response time, there maybe two method to implement this, one approach is that the process spinned on a flag indicating the arrival of the event, and the other is the process blocked on a conditional variable and wakenup by another thread when the event happens. Here we compare the effectiveness of these two methods.

Test Platform:
OS: Linux 2.6.18-1.2798.fc6 #1 SMP x86_64 GNU/Linux
CC: gcc version 4.1.1 20061011 (Red Hat 4.1.1-30)
CFLAGS: -Wall -O2
LDFLAGS: -lrt -lpthread
CPU: Dual Core AMD Opteron(tm) Processor 270
System: 2 processors

Response Time(averaged among 500 run):
usleep(1): 39928260.000000 ns
clock_nanosleep(1): 39835940.000000 ns
pthread_cond_wait: 346940.000000 ns

Source Code for Test Program:
I can't find anywhere in this blog to upload files, so until I find it, the source code may not be publicly available. Maybe you can teach me howto upload files on blogger.com. Just drop me a email.

Conclusions:
Neither usleep(1) nor clock_nanosleep(1) is good for response time, use pthread_cond_wait() is a good choice with the additional advantage of releasing CPU time for other processes/threads.

2007年3月28日星期三

how to add a directory in cvs?

There are two circumstances:

(1) the directory is empty, then use

$ cvs add dir_name

(2) the directory is not empty, in such case, you use

$ cvs import dir_name path_in_repository vendor_tag release_tag

instead.

关于 make 的一些乱七八糟的东西

Abstract


(1) How to make the output of 'make' more readable(.SILENT)?
(2) Why can't I understand some strange makefiles(Multiple Rules for One Target)?
(3) How to boost make performance(-j nr_jobs)?

4.9 Special Built-in Target Names

Certain names have special meanings if they appear as targets.

.PHONY
The prerequisites of the special target .PHONY are considered to be phony targets. When it is time to consider such a target, make will run its commands unconditionally, regardless of whether a file with that name exists or what its last-modification time is. See Phony Targets.


.SUFFIXES
The prerequisites of the special target .SUFFIXES are the list of suffixes to be used in checking for suffix rules. See Old-Fashioned Suffix Rules.


.DEFAULT
The commands specified for .DEFAULT are used for any target for which no rules are found (either explicit rules or implicit rules). See Last Resort. If .DEFAULT commands are specified, every file mentioned as a prerequisite, but not as a target in a rule, will have these commands executed on its behalf. See Implicit Rule Search Algorithm.


.SILENT
If you specify prerequisites for .SILENT, then make will not print the commands to remake those particular files before executing them. The commands for .SILENT are not meaningful.

If mentioned as a target with no prerequisites, .SILENT says not to print any commands before executing them. This usage of `.SILENT' is supported only for historical compatibility. We recommend you use the more selective ways to silence specific commands. See Command Echoing. If you want to silence all commands for a particular run of make, use the `-s' or `--silent' option (see Options Summary).


.EXPORT_ALL_VARIABLES
Simply by being mentioned as a target, this tells make to export all variables to child processes by default. See Communicating Variables to a Sub-make.


.NOTPARALLEL
If .NOTPARALLEL is mentioned as a target, then this invocation of make will be run serially, even if the `-j' option is given. Any recursively invoked make command will still be run in parallel (unless its makefile contains this target). Any prerequisites on this target are ignored.

Any defined implicit rule suffix also counts as a special target if it appears as a target, and so does the concatenation of two suffixes, such as `.c.o'. These targets are suffix rules, an obsolete way of defining implicit rules (but a way still widely used). In principle, any target name could be special in this way if you break it in two and add both pieces to the suffix list. In practice, suffixes normally begin with `.', so these special target names also begin with `.'. See Old-Fashioned Suffix Rules.


4.11 Multiple Rules for One Target

One file can be the target of several rules. All the prerequisites mentioned in all the rules are merged into one list of prerequisites for the target. If the target is older than any prerequisite from any rule, the commands are executed.

There can only be one set of commands to be executed for a file. If more than one rule gives commands for the same file, make uses the last set given and prints an error message. (As a special case, if the file's name begins with a dot, no error message is printed. This odd behavior is only for compatibility with other implementations of make... you should avoid using it). Occasionally it is useful to have the same target invoke multiple commands which are defined in different parts of your makefile; you can use double-colon rules (see Double-Colon) for this.

5.4 Parallel Execution

GNU make knows how to execute several commands at once. Normally, make will execute only one command at a time, waiting for it to finish before executing the next. However, the `-j' or `--jobs' option tells make to execute many commands simultaneously.


5.5 Errors in Commands

To ignore errors in a command line, write a `-' at the beginning of the line's text (after the initial tab). The `-' is discarded before the command is passed to the shell for execution.

For example,

     clean:
-rm -f *.o

This causes rm to continue even if it is unable to remove a file.

When you run make with the `-i' or `--ignore-errors' flag, errors are ignored in all commands of all rules. A rule in the makefile for the special target .IGNORE has the same effect, if there are no prerequisites. These ways of ignoring errors are obsolete because `-' is more flexible.

When errors are to be ignored, because of either a `-' or the `-i' flag, make treats an error return just like success, except that it prints out a message that tells you the status code the command exited with, and says that the error has been ignored.

When an error happens that make has not been told to ignore, it implies that the current target cannot be correctly remade, and neither can any other that depends on it either directly or indirectly. No further commands will be executed for these targets, since their preconditions have not been achieved.

2007年3月20日星期二

How to generate a patch file in CVS?

There is one potential problem in generating a patch file from CVS repository. The RCS keyword in source files may be expanded leading to false alarm. The cvs rdiff command has an options -k to prevent this from happening, as such:

cvs -q rdiff -u -kk -ko -r rev1 -r rev2 module_name

The patch will be output to standard output. You can use your shell's redirection mechanism to generate a patch file.

2007年3月18日星期日

Website Recommendations

燃烧的烟

http://lhyong.spaces.live.com/default.aspx?_c02_owner=1

This blog space has some wonderful articles on project management related things.

折磨人的商业计划书

原文作者:Brad Feld

翻译作者:丁丁
原文链结:The Torturous World of Powerpoint

从90年代以来,我已经看了成千上万的商业计划报告。其中绝大部分都很糟糕。不幸的是,这并不是微软Powerpoint软件的错(即使 Freelance 也不能解决这个问题)。

这其实是计划书作者的责任。Edward Tufte 是 The Visual Display of Quantitative Information 方面的权威,他认为 Powerpoint绝对是邪恶而且有害的。象 Beyond Bullets 这样的网站有助于减少这些害处,但是因为我必须在很短的时间里(通常是30到60分钟)完成非常细节内容,我想有必要更详细的介绍一下什么是“好的”计划。

几年以前,Chris Wand (他和我一起在 Mobius 投资公司工作过)列出了一些和VC商谈时必须解决的问题。如果所有创业者都自觉考虑并解答了这些问题,那事情会变得容易多了。

下面是那些应该解答的问题:

1) 你的眼光是什么?
* 你的远见是什么?
* 你要解决什么问题?对象是谁?
* 你将来想要成为什么样的人?

2) 你的市场机会是什么?市场有多大?
* 您目标的市场有多大?发展有多快?
* 这个市场有多成熟,或多不成熟?
* 你是否有资本成为这个市场前两三位?

3) 介绍你的产品和服务
* 你的产品或服务是什么?
* 解决了用户的什么问题?
* 你的产品或服务有什么特别之处?

4) 你的用户是谁?
* 谁是现在的用户?
* 谁是目标的用户?
* 理想的用户是什么样的?
* 谁会付费?
* 介绍一下某个具体用户的例子

5) 你的价值主张是什么?
* 你给用户提供了什么价值?
* 使用/买你的产品,用户的投资回收率是什么?
* 你解决了什么问题?
* 你是销售维他命,阿司匹林,还是消炎药?(奢侈品,有益的东西,还是必需品?)

6) 你如何销售?
* 销售程序是什么?周期有多长?
* 你的销售和市场方针是什么?
* 你当前的销售链是什么?

7) 你怎么吸引客户?
* 争取每个用户要花费多少钱?
* 在不同时期这个费用是否不同?为什么?
* 用户的永久价值什么?

8) 你的管理团队有谁?
* 你的管理团队有谁?
* 他们有什么经验?
* 欠缺那些环节?有什么计划去弥补?

9) 你的收入模式是什么?
* 如何赚钱
* 你的收入模式
* 需要怎样才能盈利?

10) 你现在进展到哪一步?
* 你现在进展到哪一步了?技术/产品?团队?财务/营收?
* 现在进展情况如何?现状和前景是否更清晰了?
* 你将来的计划是什么?

11) 你的融资计划是什么?
* 已经得到了什么投资?
* 希望得到多少投资?比例如何?
* 资金用在什么地方?
* 资金可以支持多久?到那时公司是否可以发展到一个重要里程碑?
* 你还打算吸引多少资金?什么时候?

12) 你的竞争对手是谁?
* 谁是你当前和潜在的竞争对手?
* 谁有可能和你竞争,谁有可能和你合作?
* 你的优势和弱点?
* 你有什么特殊之处?

13) 你有什么合作伙伴?
* 谁是你的销售或技术合作伙伴?当前?未来?
* 这些合作伙伴有多可靠?

14) 为什么适合有意的投资者?
* 和投资者的方向,经验吻合?
* 与投资者现有的投资组合有什么互补,或竞争?

15) 其它
* 成功的条件里有什么还只是假设?
* 有什么突然因素有可能一夜之间改变你的生意?新科技,新市场成员,规则法规的变化?
* 你公司的薄弱环节是什么?

===转自:http://chn.blogbeta.com/170.html===