2011年12月10日星期六

Designing for Thread Safety


Summary
This article gives you design guidelines pertaining to thread safety. It provides a background on thread safety and shows several examples of objects that are and are not thread-safe, including two illustrative applets. In addition, the article offers guidelines to help you decide when thread safety is appropriate and how best to achieve it.

Chapter 20 of Inside the Java Virtual Machine -- Thread Synchronization


One of the strengths of the Java programming language is its support for multithreading at the language level. Much of this support centers on synchronization: coordinating activities and data access among multiple threads. The mechanism that Java uses to support synchronization is the monitor. This chapter describes monitors and shows how they are used by the Java virtual machine. It describes how one aspect of monitors, the locking and unlocking of data, is supported in the instruction set.

Java:使用synchronized和Lock对象获取对象锁


在并发环境下,解决共享资源冲突问题时,可以考虑使用锁机制。
1.对象的锁
所有对象都自动含有单一的锁。
JVM负责跟踪对象被加锁的次数。如果一个对象被解锁,其计数变为0。在任务(线程)第一次给对象加锁的时候,计数变为1。每当这个相同的任务(线程)在此对象上获得锁时,计数会递增。

;; deepak's .emacs


;; deepak's .emacs

;; make it easy on eyes first ...
(set-foreground-color "gray")
(set-background-color "black")

;; where my elisp stuff is
(setq load-path (cons "D:/emacs-23.3/site-lisp" load-path)) 

Emacs as Your IDE

http://deep.syminet.com/emacside.html

This is a no-frills listing towards using Emacs as a development environment. C-x means CTRL-x. M-x means ALT-x (or ESC and then x).
You can press the TAB key almost anywhere for autocompletion. Wherever you input text, use M-p and M-n to traverse up and down the history list.
C-u is the numeric-prefix operator. To go up by 10 lines, for example, one would say C-u 10 C-p.

美国大学面试的忌讳

申请美国大学,面试是重要的一关,那么面试中的常见问题有哪些?话题有哪些?忌讳有哪些?

一、什么是面试?

简言之就是一对一的对话。一般美国常春藤盟校的每场面试会持续20-30分钟。几乎所有面试都没有固定的模式可循,因为招生官会向你提出很多意想不到的问题。学生要明白,美国的大学设立面试的目的包括:
1、探寻个性化的录取过程;
2、面向申请者的一次成功推销(校园、专业、师资信息);
3、发现申请书中难以表现的个人特质。


二、面试中的常见问题有

1、请详细介绍一下你自己。
2、你最喜欢的学科是什么?理由是什么?
3、请介绍一下你最近看的书;4、我们学校最吸引你的地方在哪里?
4、进入大学后,你的进一步计划是什么?
5、你还有什么问题要问我们(学校)的吗?

Least and the greatest fixed points

It was one of the early days in first sem in the college when I missed a few parts of the lecture as I was dozing. I went up to the nimble girl who seemed to have an agile mind that was pretty evident from her questions in the class. She attentively put down all class notes too. I thought I would borrow her class notes for a day or two. "Do write down your mobile number", I found these words somewhat unexpected as they pierced through my ears. I was certainly not going to run away with the class notes!

Well, along the years as I witnessed similar incidents, I was more and more convinced that there is nothing wrong in it. It is just that some people are more careful, particularly the members from the fairer sex. We have two very different and distinct psychologies. Some of us tend to trust in people around us and continue to do so until we find that one is unworthy of it. I fall in this group and I believe that this group shows more optimism in day to day activities than the other group which considers that one can be trusted only through good relationships that last over long period of time. The latter reflects a more conservative approach. On the other hand, I strongly believe that people around me will be very much similar in a broad sense and share a similar background and there is no reason why I should not believe in them.

This sounds to me very similar to the way we calculate the greatest and the least fixed points. Both the least and greatest fixed points are the intended solutions but for the former we start with a null set and keep on adding elements to it until we reach the fixed point. While calculating the greatest fixed point, we start with the universal set and eliminate elements until we obtain the fixed point. Both lead to solutions but the former leaves out some elements that could have been part of our solution. So we fail to get to know a few people who could have been closer to us if we initialize the basket of our trustworthy people with no one. The old may argue that it is just my youth which ventures and time might change things as I move along.

2011年12月8日星期四

GNU make 指南(转)

原文出处

http://www.lisoleg.net/lisoleg/applications/gmake.htm


译者按: 本文是一篇介绍 GNU Make 的文章,读完后读者应该基本掌握了 make 的用法。而 make 是所有想在 Unix (当然也包括 Linux )系统上编程的用户必须掌握的工具。如果你写的程序中没有用到 make ,则说明你写的程序只是个人的练习程序,不具有任何实用的价值。也许这么说有点 儿偏激,但 make 实在是应该用在任何稍具规模的程序中的。希望本文可以为中国的 Unix 编程初学者提供一点儿有用的资料。中国的 Linux 用户除了学会安装红帽子以外, 实在应该尝试写一些有用的程序。个人想法,大家参考。

中国传统色彩名录

████ 粉红,即浅红色。别称:妃色 杨妃色 湘妃色 妃红色 
████ 妃色 妃红色:古同“绯”,粉红色。杨妃色 湘妃色 粉红皆同义。 
████ 品红:比大红浅的红色 (quester注:这 里的“品红”估计是指的“一品红”,是基于大红色系的,和现在我们印刷用色的“品红M100”不是一个概念)
████ 桃红,桃花的颜色,比粉红略鲜润的颜色。 (quester 注:不大于M70的色彩,有时可加入适量黄色)
████ 海棠红,淡紫红色、较桃红色深一些,是非常妩媚娇艳的颜色。 
████ 石榴红:石榴花的颜色,高色度和纯度的红色。 
████ 樱桃色:鲜红色 
████ 银红:银朱和粉红色颜料配成的颜色。多用来形容有光泽的各种红色,尤指有光泽浅红。 
████ 大红:正红色,三原色中的红,传统的中国红,又称绛色 (quester注:RGB 色中的 R255 系列明度)
████ 绛紫:紫中略带红的颜色 
████ 绯红:艳丽的深红 
████ 胭脂:1,女子装扮时用的胭脂的颜色。2,国画暗红色颜料 
████ 朱红:朱砂的颜色,比大红活泼,也称铅朱 朱色 丹色 (quester注:在YM对等的情况下,适量减少 红色的成分就是该色的色彩系列感觉)
████ 丹:丹砂的鲜艳红色 
████ 彤:赤色 
████ 茜色:茜草染的色彩,呈深红色 
████ 火红:火焰的红色,赤色 
████ 赫赤:深红,火红。泛指赤色、火红色。 
████ 嫣红:鲜艳的红色 
████ 洋红:色橘红 (quester注:这个色彩方向不太对,通常洋红指的是倾向于M100系列的红色,应该 削弱黄色成分。)
████ 炎:引申为红色。 
████ 赤:本义火的颜色,即红色 
████ 绾:绛色;浅绛色。 
████ 枣红:即深红 (quester注:色相不变,是深浅变化)
████ 檀:浅红色,浅绛色。 
████ 殷红:发黑的红色。 
████ 酡红:像饮酒后脸上泛现的红色,泛指脸红 
████ 酡颜:饮酒脸红的样子。亦泛指脸红色 



2011年12月7日星期三

所谓幸福感,其实有两种选择


所谓幸福感,其实有两种选择:
(1)年少时少努力,感觉很幸福;成年时工作不如意,收入少,社会地位低。等发现不幸福的时候,想再回去读书提升自己,可是有了家庭的拖累与年龄的弱势,已经无力回天了。
(2)年少时勤奋努力,感觉很痛苦;成年时能够找到好的工作,收入多,社会地位高。这时候,也有两条路可走:(a)开始痛骂小时候那些不幸福的往事,并让自己的小孩走上第一条道路;(b)明白自己现在的幸福是第二条道路培育出来的结果,所以坚持让自己的后代走第二条道路。
据我的观察,从中国出来留学的几乎都是走第二条道路而成功的,可是其中低智慧的会踏上(a),高智慧的会继续奉行(b)。